Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
tompretty committed Feb 12, 2021
1 parent 4d5d7ee commit cf2da92
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions src/create-reminder-signup/lambda/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ const createSignup = async <T extends BaseSignupRequest>(
body: 'Invalid body',
};
}
console.log(signupRequest);

const token = await identityAccessTokenPromise;
const pool = await dbConnectionPoolPromise;
Expand Down
1 change: 1 addition & 0 deletions src/create-reminder-signup/lambda/local.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function runLocal() {
body: JSON.stringify({
email: '[email protected]',
reminderPeriod: '2021-01-01',
reminderCreatedAt: 'foo',
reminderFrequencyMonths: 3,
reminderPlatform: 'WEB',
reminderComponent: 'EPIC',
Expand Down
18 changes: 11 additions & 7 deletions src/create-reminder-signup/lambda/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,27 @@ function isValidEmail(email: string): boolean {
return re.test(email.toLowerCase());
}

type ReminderPeriod = string;
type DateString = string;

function isValidReminderPeriod(reminderPeriod: string): boolean {
const date = Date.parse(reminderPeriod);
function isValidDateString(dateString: string): boolean {
console.log(dateString);
const date = Date.parse(dateString);
console.log('after!');
return !isNaN(date);
}

export interface BaseSignupRequest {
email: Email;
country?: string;
reminderCreatedAt?: string;
reminderCreatedAt: DateString;
reminderPlatform: ReminderPlatform;
reminderComponent: ReminderComponent;
reminderStage: ReminderStage;
reminderOption?: string;
}

export interface OneOffSignupRequest extends BaseSignupRequest {
reminderPeriod: ReminderPeriod;
reminderPeriod: DateString;
}

export interface RecurringSignupRequest extends BaseSignupRequest {
Expand All @@ -74,8 +76,8 @@ export const oneOffSignupValidator = createDetailedValidator<OneOffSignupRequest
constraints: {
Email: (email: string) =>
isValidEmail(email) ? null : 'Invalid email',
ReminderPeriod: (reminderPeriod: string) =>
isValidReminderPeriod(reminderPeriod) ? null : 'Invalid date',
DateString: (dateString: string) =>
isValidDateString(dateString) ? null : 'Invalid date',
},
},
);
Expand All @@ -87,6 +89,8 @@ export const recurringSignupValidator = createDetailedValidator<RecurringSignupR
constraints: {
Email: (email: string) =>
isValidEmail(email) ? null : 'Invalid email',
DateString: (dateString: string) =>
isValidDateString(dateString) ? null : 'Invalid date',
},
},
);
Expand Down

0 comments on commit cf2da92

Please sign in to comment.