Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions functions/src/controllers/application_controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
16 changes: 9 additions & 7 deletions functions/src/types/application_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -31,6 +32,7 @@ export interface StringValidation {
required?: boolean;
minLength?: number;
maxLength?: number;
pattern?: string;
}

export interface NumberValidation {
Expand Down Expand Up @@ -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 {
Expand Down