Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/harsh daniel/vsr page 2 #30

Merged
merged 22 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
b90a025
added mongo and backend support for VSR page 2
HarshGurnani Feb 26, 2024
24007bf
frontend changes in progress
HarshGurnani Feb 28, 2024
d4f9aad
merging main
HarshGurnani Feb 29, 2024
9371adf
mostly finished frontend; todo: fix petCompanion and serviceConnected…
HarshGurnani Feb 29, 2024
9b0e1dc
new component in progress
HarshGurnani Mar 2, 2024
e12f034
changed some Mulitple Choice components to Binary Choice; todo - debu…
HarshGurnani Mar 4, 2024
513f8d9
fixed binary choice option for vsr
holychickencow Mar 5, 2024
e763452
fixed how did you find out question
holychickencow Mar 6, 2024
4bdd1f0
Merge branch 'main' into feature/harsh-daniel/vsr-page-2
HarshGurnani Mar 7, 2024
7010cf5
minor bug fixes; to fix: we are able to hit submit even when everythi…
HarshGurnani Mar 8, 2024
4c90d03
fixed page increment
HarshGurnani Mar 11, 2024
bc1fb07
submit button greyed out if all required fields aren't filled
holychickencow Mar 12, 2024
0557b40
linting
HarshGurnani Mar 13, 2024
ddded4f
Bugfixes, remove commented-out code
benjaminJohnson2204 Mar 14, 2024
256ab6b
Lint fix
benjaminJohnson2204 Mar 14, 2024
5e08122
Merge branch 'main' into feature/harsh-daniel/vsr-page-2
benjaminJohnson2204 Mar 14, 2024
ff95bfd
Merge branch 'main' into feature/harsh-daniel/vsr-page-2
benjaminJohnson2204 Mar 14, 2024
08faed5
Refactor BinaryChoice component
benjaminJohnson2204 Mar 14, 2024
abf6918
VSR pages 2/3 integration fixes
benjaminJohnson2204 Mar 14, 2024
6a4a303
fixed phone number and email issues
HarshGurnani Mar 16, 2024
2d1127b
merging main and fixing email and phone number issues:
HarshGurnani Mar 16, 2024
dd076f3
Fix input validation with email and binary choice fields
benjaminJohnson2204 Mar 19, 2024
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
50 changes: 27 additions & 23 deletions backend/src/controllers/vsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,20 @@ export const createVSR: RequestHandler = async (req, res, next) => {
employmentStatus,
incomeLevel,
sizeOfHome,
hearFrom,
petCompanion,
militaryId,
lastRank,
serviceConnected,
dischargeStatus,
email,
phoneNumber,
zipCode,
state,
city,
streetAddress,
city,
state,
zipCode,
phoneNumber,
email,
branch,
conflicts,
dischargeStatus,
serviceConnected,
lastRank,
militaryID,
petCompanion,
hearFrom,
selectedFurnitureItems,
additionalItems,
} = req.body;
Expand All @@ -69,25 +71,27 @@ export const createVSR: RequestHandler = async (req, res, next) => {
employmentStatus,
incomeLevel,
sizeOfHome,
streetAddress,
city,
state,
zipCode,
phoneNumber,
email,
branch,
conflicts,
dischargeStatus,
serviceConnected,
lastRank,
militaryID,
petCompanion,
hearFrom,

// Use current date as timestamp for received & updated
dateReceived: currentDate,
lastUpdated: currentDate,

status: "Received",

hearFrom,
petCompanion,
militaryId,
lastRank,
serviceConnected,
dischargeStatus,
email,
phoneNumber,
zipCode,
state,
city,
streetAddress,
selectedFurnitureItems,
additionalItems,
});
Expand Down
18 changes: 9 additions & 9 deletions backend/src/models/vsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ const furntitureInputSchema = new Schema({

const vsrSchema = new Schema({
name: { type: String, required: true },
gender: { type: String, require: true },
age: { type: Number, require: true },
gender: { type: String, required: true },
age: { type: Number, required: true },
maritalStatus: { type: String, required: true },
spouseName: { type: String },
agesOfBoys: { type: [Number] },
agesOfGirls: { type: [Number] },
ethnicity: { type: [String], require: true },
employmentStatus: { type: String, require: true },
incomeLevel: { type: String, require: true },
sizeOfHome: { type: String, require: true },
ethnicity: { type: [String], required: true },
employmentStatus: { type: String, required: true },
incomeLevel: { type: String, required: true },
sizeOfHome: { type: String, required: true },
streetAddress: { type: String, required: true },
city: { type: String, required: true },
state: { type: String, required: true },
Expand All @@ -26,10 +26,10 @@ const vsrSchema = new Schema({
branch: { type: [String], required: true },
conflicts: { type: [String], required: true },
dischargeStatus: { type: String, required: true },
serviceConnected: { type: String, required: true },
serviceConnected: { type: Boolean, required: true },
lastRank: { type: String, required: true },
militaryId: { type: Number, required: true },
petCompanion: { type: String, required: true },
militaryID: { type: Number, required: true },
petCompanion: { type: Boolean, required: true },
hearFrom: { type: String, required: true },
selectedFurnitureItems: { type: [furntitureInputSchema], required: true },
additionalItems: { type: String, required: false },
Expand Down
178 changes: 99 additions & 79 deletions backend/src/validators/vsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,65 +82,40 @@ const makeSizeOfHomeValidator = () =>
.isString()
.withMessage("Size of Home must be a string");

const ALLOWED_STATUSES = [
"Received",
"Appointment Scheduled",
"Approved",
"Resubmit",
"No-show / Incomplete",
"Archived",
];

const updateStatusValidator = () =>
body("status")
const makeStreetAddressValidator = () =>
body("streetAddress")
.exists({ checkFalsy: true })
.withMessage("Status is required")
.withMessage("Address is required")
.isString()
.withMessage("Status must be a string")
.isIn(ALLOWED_STATUSES)
.withMessage("Status must be one of the allowed options");
.withMessage("Address must be a string");

const makeHearFromValidator = () =>
body("hearFrom")
const makeCityValidator = () =>
body("city")
.exists({ checkFalsy: true })
.withMessage("Hear from is required")
.withMessage("City is required")
.isString()
.withMessage("Hear from must be a string");

const makePetCompanionValidator = () =>
body("petCompanion")
.exists({ checkFalsy: true })
.withMessage("Pet companion is required")
.isBoolean()
.withMessage("Pet companion must be a boolean");

const makeMilitaryIdValidator = () =>
body("militaryId")
.exists({ checkFalsy: true })
.withMessage("Military Id is required")
.isInt()
.withMessage("Military Id must be an integer");
.withMessage("City must be a string");

const makeLastRankValidator = () =>
body("lastRank")
const makeStateValidator = () =>
body("state")
.exists({ checkFalsy: true })
.withMessage("Last rank is required")
.withMessage("State is required")
.isString()
.withMessage("Last rank must be a string");
.withMessage("State must be a string");

const makeServiceConnectedValidator = () =>
body("serviceConnected")
const makeZipCodeValidator = () =>
body("zipCode")
.exists({ checkFalsy: true })
.withMessage("Service connected is required")
.isBoolean()
.withMessage("Service connected must be a boolean");
.withMessage("Zip Code is required")
.isInt({ min: 10000 })
.withMessage("Zip Code must be a 5 digit integer");

const makeDischargeStatusValidator = () =>
body("dischargeStatus")
const makePhoneNumberValidator = () =>
body("phoneNumber")
.exists({ checkFalsy: true })
.withMessage("Discharge status is required")
.withMessage("Phone Number is required")
.isString()
.withMessage("Discharge status must be a string");
.withMessage("Phone number must be a string");

const makeEmailValidator = () =>
body("email")
Expand All @@ -149,40 +124,83 @@ const makeEmailValidator = () =>
.isString()
.withMessage("Email must be a string");

const makePhoneNumberValidator = () =>
body("phoneNumber")
const makeBranchValidator = () =>
body("branch")
.exists({ checkFalsy: true })
.withMessage("Phone number is required")
.isString()
.withMessage("Phone number must be a string");
.withMessage("Branch is required")
.isArray()
.withMessage("Branch must be an array")
.custom((branches: string[]) => branches.every((branch) => typeof branch == "string"))
.withMessage("Each branch must be a string");

const makeZipCodeValidator = () =>
body("zipCode")
const makeConflictsValidator = () =>
body("conflicts")
.exists({ checkFalsy: true })
.withMessage("Zip code is required")
.isInt({ min: 0 })
.withMessage("Zip code must be a positive integer");
.withMessage("Conflict(s) is required")
.isArray()
.withMessage("Conflict(s) must be an array")
.custom((conflicts: string[]) => conflicts.every((conflict) => typeof conflict === "string"))
.withMessage("Each conflict must be a string");

const makeStateValidator = () =>
body("state")
const makeDischargeStatusValidator = () =>
body("dischargeStatus")
.exists({ checkFalsy: true })
.withMessage("State is required")
.withMessage("Discharge Status is required")
.isString()
.withMessage("State must be a string");
.withMessage("Discharge Status must be a string");

const makeCityValidator = () =>
body("city")
const makeServiceConnectedValidator = () =>
body("serviceConnected")
.exists({ checkFalsy: false })
.withMessage("Service Connected is required")
.isBoolean()
.withMessage("Service Connected must be a boolean");

const makeLastRankValidator = () =>
body("lastRank")
.exists({ checkFalsy: true })
.withMessage("City is required")
.withMessage("Last rank is required")
.isString()
.withMessage("City must be a string");
.withMessage("Last rank must be a string");

const makeStreetAddressValidator = () =>
body("streetAddress")
const makeMilitaryIDValidator = () =>
body("militaryID")
.exists({ checkFalsy: true })
.withMessage("Military ID is required")
.isInt()
.withMessage("Military ID must be an integer");

const makePetCompanionValidator = () =>
body("petCompanion")
.exists({ checkFalsy: false })
.withMessage("Pet interest is required")
.isBoolean()
.withMessage("Pet interest must be a boolean");

const makeHearFromValidator = () =>
body("hearFrom")
.exists({ checkFalsy: true })
.withMessage("Referral source is required")
.isString()
.withMessage("Referral source must be a string");

const ALLOWED_STATUSES = [
"Received",
"Appointment Scheduled",
"Approved",
"Resubmit",
"No-show / Incomplete",
"Archived",
];

const updateStatusValidator = () =>
body("status")
.exists({ checkFalsy: true })
.withMessage("Street address is required")
.withMessage("Status is required")
.isString()
.withMessage("Street address must be a string");
.withMessage("Status must be a string")
.isIn(ALLOWED_STATUSES)
.withMessage("Status must be one of the allowed options");

export const createVSR = [
makeNameValidator(),
Expand All @@ -196,18 +214,20 @@ export const createVSR = [
makeEmploymentStatusValidator(),
makeIncomeLevelValidator(),
makeSizeOfHomeValidator(),
makeHearFromValidator(),
makePetCompanionValidator(),
makeMilitaryIdValidator(),
makeLastRankValidator(),
makeServiceConnectedValidator(),
makeDischargeStatusValidator(),
makeEmailValidator(),
makePhoneNumberValidator(),
makeZipCodeValidator(),
makeStateValidator(),
makeCityValidator(),
makeStreetAddressValidator(),
makeCityValidator(),
makeStateValidator(),
makeZipCodeValidator(),
makePhoneNumberValidator(),
makeEmailValidator(),
makeBranchValidator(),
makeConflictsValidator(),
makeDischargeStatusValidator(),
makeServiceConnectedValidator(),
makeLastRankValidator(),
makeMilitaryIDValidator(),
makePetCompanionValidator(),
makeHearFromValidator(),
];

export const updateStatus = [updateStatusValidator()];
10 changes: 5 additions & 5 deletions frontend/src/api/VSRs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface VSRJson {
dischargeStatus: string;
serviceConnected: boolean;
lastRank: string;
militaryId: number;
militaryID: number;
petCompanion: boolean;
selectedFurnitureItems: FurnitureInput[];
additionalItems: string;
Expand Down Expand Up @@ -67,7 +67,7 @@ export interface VSR {
dischargeStatus: string;
serviceConnected: boolean;
lastRank: string;
militaryId: number;
militaryID: number;
petCompanion: boolean;
selectedFurnitureItems: FurnitureInput[];
additionalItems: string;
Expand Down Expand Up @@ -100,11 +100,11 @@ export interface CreateVSRRequest {
dischargeStatus: string;
serviceConnected: boolean;
lastRank: string;
militaryId: number;
militaryID: number;
petCompanion: boolean;
hearFrom: string;
selectedFurnitureItems: FurnitureInput[];
additionalItems: string;
hearFrom: string;
}

function parseVSR(vsr: VSRJson) {
Expand Down Expand Up @@ -132,7 +132,7 @@ function parseVSR(vsr: VSRJson) {
dischargeStatus: vsr.dischargeStatus,
serviceConnected: vsr.serviceConnected,
lastRank: vsr.lastRank,
militaryId: vsr.militaryId,
militaryID: vsr.militaryID,
petCompanion: vsr.petCompanion,
selectedFurnitureItems: vsr.selectedFurnitureItems,
additionalItems: vsr.additionalItems,
Expand Down
Loading
Loading