From 183b5b141094103152caa1449d574a54049919d5 Mon Sep 17 00:00:00 2001 From: seaerchin Date: Wed, 7 Jul 2021 16:32:00 +0800 Subject: [PATCH] chore(form.utils): addressed PR comments --- src/app/modules/form/admin-form/admin-form.service.ts | 4 ++-- src/app/modules/form/form.utils.ts | 4 +++- src/types/form.ts | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/app/modules/form/admin-form/admin-form.service.ts b/src/app/modules/form/admin-form/admin-form.service.ts index 99fc1e2ab4..ab584ce26d 100644 --- a/src/app/modules/form/admin-form/admin-form.service.ts +++ b/src/app/modules/form/admin-form/admin-form.service.ts @@ -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( diff --git a/src/app/modules/form/form.utils.ts b/src/app/modules/form/form.utils.ts index 947863344f..81a0f4a0b7 100644 --- a/src/app/modules/form/form.utils.ts +++ b/src/app/modules/form/form.utils.ts @@ -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 => { +export const isOnboardedForm = ( + form: T, +): form is IOnboardedForm => { return !!form.msgSrvcName } diff --git a/src/types/form.ts b/src/types/form.ts index b546d718db..12d1ec279d 100644 --- a/src/types/form.ts +++ b/src/types/form.ts @@ -150,7 +150,9 @@ export interface IForm { emails?: string[] | string } -export type IOnboardedForm = SetRequired +export type IOnboardedForm = T & { + msgSrvcName: string +} export type FormSettings = Pick< IFormDocument,