Skip to content

Commit

Permalink
chore(form.utils): addressed PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
seaerchin committed Jul 14, 2021
1 parent 876e096 commit 183b5b1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/app/modules/form/admin-form/admin-form.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1092,13 +1092,13 @@ export const shouldUpdateFormField = (
IPopulatedForm,
PossibleDatabaseError | SmsLimitExceededError
> => {
const formAdminId = String(form.admin._id)

// Field can always update if it's not a verifiable field or if the form has been onboarded
if (!isVerifiableMobileField(formField) || isOnboardedForm(form)) {
return okAsync(form)
}

const formAdminId = String(form.admin._id)

// If the form admin has exceeded the sms limit
// And the form is not onboarded, refuse to update the field
return SmsService.retrieveFreeSmsCounts(formAdminId).andThen(
Expand Down
4 changes: 3 additions & 1 deletion src/app/modules/form/form.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export const getLogicById = (
}

// Typeguard to check if a form has a message service id
export const isOnboardedForm = (form: IForm): form is IOnboardedForm<IForm> => {
export const isOnboardedForm = <T extends IForm = IForm>(
form: T,
): form is IOnboardedForm<T> => {
return !!form.msgSrvcName
}
4 changes: 3 additions & 1 deletion src/types/form.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export interface IForm {
emails?: string[] | string
}

export type IOnboardedForm<T extends IForm> = SetRequired<T, 'msgSrvcName'>
export type IOnboardedForm<T extends IForm> = T & {
msgSrvcName: string
}

export type FormSettings = Pick<
IFormDocument,
Expand Down

0 comments on commit 183b5b1

Please sign in to comment.