diff --git a/server/data/cohonFC_data.csv b/server/data/cohonFCData.csv similarity index 100% rename from server/data/cohonFC_data.csv rename to server/data/cohonFCData.csv diff --git a/server/data/fairfax_data.csv b/server/data/fairfaxData.csv similarity index 100% rename from server/data/fairfax_data.csv rename to server/data/fairfaxData.csv diff --git a/server/data/tepperFC_data.csv b/server/data/tepperFCData.csv similarity index 100% rename from server/data/tepperFC_data.csv rename to server/data/tepperFCData.csv diff --git a/server/data/wiegand_data.csv b/server/data/wiegandData.csv similarity index 100% rename from server/data/wiegand_data.csv rename to server/data/wiegandData.csv diff --git a/server/src/controllers/controllers.ts b/server/src/controllers/controllers.ts index 11b05cb..15358b0 100644 --- a/server/src/controllers/controllers.ts +++ b/server/src/controllers/controllers.ts @@ -35,8 +35,9 @@ export const getAllOccupancy = async (req: Request, res: Response) => { }; export const getOccupancy = async (req: Request, res: Response) => { + const {gym} = req.params; try { - const {gym} = req.params; + await predict.validateGymReq(gym); const mostRecentRecord: OccupancyRecord = await db.getRecentRecord(gym); // const finalOccupancy : BTG_Occupancy = {count: mostRecentRecord.occupancy}; @@ -73,8 +74,8 @@ export const predictOccupancy = async (req: Request, res: Response) => { // TODO: Get all records from a specific gym export const getRecords = async (req: Request, res: Response) => { const { gym } = req.params; - try { + await predict.validateGymReq(gym); const data = await db.getRecords(gym); res.status(HTTP_STATUS.OK).json(data); } catch (error) { @@ -102,8 +103,9 @@ export const getAllMetadata = async (req: Request, res: Response) => { }; export const getMetadata = async (req: Request, res: Response) => { + const {gym} = req.params; try { - const {gym} = req.params; + await predict.validateGymReq(gym); const meta : Metadata = await db.getMetadata(gym); res.status(HTTP_STATUS.OK).json(meta); } catch (error) { diff --git a/server/src/services/predict_occupancy.ts b/server/src/services/predictOccupancy.ts similarity index 92% rename from server/src/services/predict_occupancy.ts rename to server/src/services/predictOccupancy.ts index b172bad..7aa3f7a 100644 --- a/server/src/services/predict_occupancy.ts +++ b/server/src/services/predictOccupancy.ts @@ -73,3 +73,10 @@ export const validatePredictReq = async (gym: string, timestamp: string) => { throw new Error(`Invalid Gym ${gym}`); } }; + +export const validateGymReq = async (gym: string) => { + const names = await db.getAllNames(); + if (!names.includes(gym)) { + throw new Error(`Inavalid Gym ${gym}`); + } +}; diff --git a/server/src/utils/write_csv.ts b/server/src/utils/writeCsv.ts similarity index 100% rename from server/src/utils/write_csv.ts rename to server/src/utils/writeCsv.ts