Skip to content

Commit

Permalink
merging main and fixing email and phone number issues:
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshGurnani committed Mar 16, 2024
2 parents 6a4a303 + abf6918 commit 2d1127b
Show file tree
Hide file tree
Showing 35 changed files with 1,119 additions and 205 deletions.
266 changes: 266 additions & 0 deletions backend/__tests__/furnitureItems.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,266 @@
[
{
"category": "bedroom",
"name": "Twin mat.",
"allowMultiple": true,
"categoryIndex": 1
},
{
"category": "bedroom",
"name": "Full Mat.",
"allowMultiple": true,
"categoryIndex": 2
},
{
"category": "bedroom",
"name": "Queen Mat.",
"allowMultiple": true,
"categoryIndex": 3
},
{
"category": "bedroom",
"name": "King Mat.",
"allowMultiple": true,
"categoryIndex": 4
},
{
"category": "bedroom",
"name": "Matching Box Spring(s)",
"allowMultiple": true,
"categoryIndex": 5
},
{
"category": "bedroom",
"name": "Matching Bed Frame(s)",
"allowMultiple": true,
"categoryIndex": 6
},
{
"category": "bedroom",
"name": "Night Stand(s)",
"allowMultiple": true,
"categoryIndex": 7
},
{
"category": "bedroom",
"name": "Sheet Set(s)",
"allowMultiple": true,
"categoryIndex": 8
},
{
"category": "bedroom",
"name": "Blankets",
"allowMultiple": true,
"categoryIndex": 9
},
{
"category": "bedroom",
"name": "Dresser",
"allowMultiple": false,
"categoryIndex": 10
},
{
"category": "bathroom",
"name": "Bath Rug(s)",
"allowMultiple": true,
"categoryIndex": 1
},
{
"category": "bathroom",
"name": "Towel(s)",
"allowMultiple": true,
"categoryIndex": 2
},
{
"category": "bathroom",
"name": "Wash Cloth(s)",
"allowMultiple": true,
"categoryIndex": 3
},
{
"category": "kitchen",
"name": "Dish Set(s)",
"allowMultiple": true,
"categoryIndex": 1
},
{
"category": "kitchen",
"name": "Glasses",
"allowMultiple": true,
"categoryIndex": 2
},
{
"category": "kitchen",
"name": "Stove (Gas)",
"allowMultiple": false,
"categoryIndex": 3
},
{
"category": "kitchen",
"name": "Stove (Electric)",
"allowMultiple": false,
"categoryIndex": 4
},
{
"category": "kitchen",
"name": "Cups",
"allowMultiple": false,
"categoryIndex": 5
},
{
"category": "kitchen",
"name": "Silverware",
"allowMultiple": false,
"categoryIndex": 6
},
{
"category": "kitchen",
"name": "Pots and Pans",
"allowMultiple": false,
"categoryIndex": 7
},
{
"category": "kitchen",
"name": "Cooking Utensils",
"allowMultiple": false,
"categoryIndex": 8
},
{
"category": "kitchen",
"name": "Can Opener",
"allowMultiple": false,
"categoryIndex": 9
},
{
"category": "kitchen",
"name": "Refrigerator",
"allowMultiple": false,
"categoryIndex": 10
},
{
"category": "kitchen",
"name": "Microwave",
"allowMultiple": false,
"categoryIndex": 11
},
{
"category": "kitchen",
"name": "Toaster",
"allowMultiple": false,
"categoryIndex": 12
},
{
"category": "kitchen",
"name": "Coffee Pot",
"allowMultiple": false,
"categoryIndex": 13
},
{
"category": "living room",
"name": "Desk Lamp(s)",
"allowMultiple": true,
"categoryIndex": 1
},
{
"category": "living room",
"name": "Floor Lamp(s)",
"allowMultiple": true,
"categoryIndex": 2
},
{
"category": "living room",
"name": "End Table(s)",
"allowMultiple": true,
"categoryIndex": 3
},
{
"category": "living room",
"name": "Couch/Loveseat",
"allowMultiple": true,
"categoryIndex": 4
},
{
"category": "living room",
"name": "Rug(s)",
"allowMultiple": true,
"categoryIndex": 5
},
{
"category": "living room",
"name": "Couch",
"allowMultiple": false,
"categoryIndex": 6
},
{
"category": "living room",
"name": "Chair",
"allowMultiple": false,
"categoryIndex": 7
},
{
"category": "living room",
"name": "Coffee Table",
"allowMultiple": false,
"categoryIndex": 8
},
{
"category": "living room",
"name": "TV",
"allowMultiple": false,
"categoryIndex": 9
},
{
"category": "living room",
"name": "TV Stand",
"allowMultiple": false,
"categoryIndex": 10
},
{
"category": "living room",
"name": "TV/Stereo Wall Unit",
"allowMultiple": false,
"categoryIndex": 11
},
{
"category": "living room",
"name": "Desk",
"allowMultiple": false,
"categoryIndex": 12
},
{
"category": "dining room",
"name": "Chairs",
"allowMultiple": true,
"categoryIndex": 1
},
{
"category": "dining room",
"name": "China Cabinet/Buffet",
"allowMultiple": false,
"categoryIndex": 2
},
{
"category": "dining room",
"name": "Table",
"allowMultiple": false,
"categoryIndex": 3
},
{
"category": "other",
"name": "Dryer (Gas)",
"allowMultiple": false,
"categoryIndex": 1
},
{
"category": "other",
"name": "Dryer (Electric)",
"allowMultiple": false,
"categoryIndex": 2
},
{
"category": "other",
"name": "Washer",
"allowMultiple": false,
"categoryIndex": 3
}
]
2 changes: 2 additions & 0 deletions backend/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cors from "cors";
import express, { NextFunction, Request, Response } from "express";
import { isHttpError } from "http-errors";
import vsrRoutes from "../src/routes/vsr";
import furnitureItemRoutes from "../src/routes/furnitureItem";
import { userRouter } from "src/routes/users";
import env from "src/util/validateEnv";

Expand Down Expand Up @@ -54,5 +55,6 @@ app.use((error: unknown, req: Request, res: Response, next: NextFunction) => {
});

app.use("/api/vsr", vsrRoutes);
app.use("/api/furnitureItems", furnitureItemRoutes);

export default app;
16 changes: 16 additions & 0 deletions backend/src/controllers/furnitureItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { RequestHandler } from "express";
import createHttpError from "http-errors";
import FurnitureItemModel from "src/models/furnitureItem";

export const getFurnitureItems: RequestHandler = async (req, res, next) => {
try {
const furnitureItems = await FurnitureItemModel.find();

if (furnitureItems === null) {
throw createHttpError(404, "Furniture items not found");
}
res.status(200).json(furnitureItems);
} catch (error) {
next(error);
}
};
25 changes: 24 additions & 1 deletion backend/src/controllers/vsr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ export const createVSR: RequestHandler = async (req, res, next) => {
militaryID,
petCompanion,
hearFrom,
selectedFurnitureItems,
additionalItems,
} = req.body;

try {
Expand Down Expand Up @@ -87,8 +89,12 @@ export const createVSR: RequestHandler = async (req, res, next) => {
// Use current date as timestamp for received & updated
dateReceived: currentDate,
lastUpdated: currentDate,
});

status: "Received",

selectedFurnitureItems,
additionalItems,
});
// 201 means a new resource has been created successfully
// the newly created VSR is sent back to the user
res.status(201).json(vsr);
Expand All @@ -97,6 +103,23 @@ export const createVSR: RequestHandler = async (req, res, next) => {
}
};

export const updateStatus: RequestHandler = async (req, res, next) => {
try {
// extract any errors that were found by the validator
const errors = validationResult(req);
const { status } = req.body;

// if there are errors, then this function throws an exception
validationErrorParser(errors);

const { id } = req.params;
const vsr = await VSRModel.findByIdAndUpdate(id, { status }, { new: true });
res.status(200).json(vsr);
} catch (error) {
next(error);
}
};

export const getAllVSRS: RequestHandler = async (req, res, next) => {
try {
const vsrs = await VSRModel.find();
Expand Down
13 changes: 13 additions & 0 deletions backend/src/models/furnitureItem.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { InferSchemaType, Schema, model } from "mongoose";

const furnitureItemSchema = new Schema({
_id: { type: String, required: true },
category: { type: String, required: true },
name: { type: String, required: true },
allowMultiple: { type: Boolean, required: true },
categoryIndex: { type: Number, required: true },
});

type FurnitureItem = InferSchemaType<typeof furnitureItemSchema>;

export default model<FurnitureItem>("FurnitureItem", furnitureItemSchema);
Loading

0 comments on commit 2d1127b

Please sign in to comment.