Skip to content

Commit

Permalink
Merge branch 'main' into feature/sydney-steven/login-mobile
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminJohnson2204 committed Mar 23, 2024
2 parents da6f2b7 + 2839704 commit b659e1a
Show file tree
Hide file tree
Showing 10 changed files with 772 additions and 135 deletions.
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

0 comments on commit b659e1a

Please sign in to comment.