From 14c3ca799a859a744193ebac0b675419d93a97bf Mon Sep 17 00:00:00 2001 From: Kezia Date: Fri, 16 May 2025 18:29:16 -0400 Subject: [PATCH] added new validation pattern --- .../src/controllers/application_controller.ts | 14 ++++++++++++-- functions/src/types/application_types.ts | 16 +++++++++------- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/functions/src/controllers/application_controller.ts b/functions/src/controllers/application_controller.ts index def613a..898b1b3 100644 --- a/functions/src/controllers/application_controller.ts +++ b/functions/src/controllers/application_controller.ts @@ -462,8 +462,18 @@ function validateStringValue(fieldValue: string | any, question: Question) { message: `Must be less than ${validation.maxLength} character(s)`, }); } - // other string validation if needed - // ... + + // validate pattern + if (validation.pattern) { + const regex = new RegExp(validation.pattern); + if (!regex.test(fieldValue)) { + errors.push({ + field_id: `${question.id}`, + message: `Not a valid ${question.text}.`, + }); + } + } + return errors; } diff --git a/functions/src/types/application_types.ts b/functions/src/types/application_types.ts index 182ef08..0f1c82e 100644 --- a/functions/src/types/application_types.ts +++ b/functions/src/types/application_types.ts @@ -6,16 +6,17 @@ export enum APPLICATION_STATUS { SUBMITTED = "submitted", WAITLISTED = "waitlisted", REJECTED = "rejected", - ACCEPTED = "accepted" + ACCEPTED = "accepted", + CONFIRMED_RSVP = "confirmed rsvp", } /** * State for part to show in the web UI of GH Portal. */ export enum APPLICATION_STATES { - PROFILE = "PROFILE", - INQUIRY = "INQUIRY", - ADDITIONAL_QUESTION = "ADDITIONAL_QUESTION", + PROFILE = "profile", + INQUIRY = "inquiry", + ADDITIONAL_QUESTION = "additional", } export enum QUESTION_TYPE { @@ -31,6 +32,7 @@ export interface StringValidation { required?: boolean; minLength?: number; maxLength?: number; + pattern?: string; } export interface NumberValidation { @@ -64,14 +66,14 @@ export type ValidationTypeMap = { }; export interface Question { - id?: string; + id: string; order: number; - state: APPLICATION_STATES; text: string; type: QUESTION_TYPE; validation: ValidationTypeMap[Question["type"]]; - + placeholder?: string; options?: string[]; // for dropdown only + state: APPLICATION_STATES; } export interface FileInfo {