From cf6535eca71c31fdddee1a6b37318f5355a0871b Mon Sep 17 00:00:00 2001 From: elit04 <elit04@fu-berlin.de> Date: Mon, 24 Jan 2022 11:24:18 -0500 Subject: [PATCH] more checks --- server/src/controllers/boat.controllers.ts | 15 ++++++++++++++- .../controllers/createLogEntry.controllers.ts | 5 +++-- server/src/controllers/user.controllers.ts | 18 ++++++++++++++++++ 3 files changed, 35 insertions(+), 3 deletions(-) diff --git a/server/src/controllers/boat.controllers.ts b/server/src/controllers/boat.controllers.ts index fd0df68..852db6c 100644 --- a/server/src/controllers/boat.controllers.ts +++ b/server/src/controllers/boat.controllers.ts @@ -33,11 +33,24 @@ const createBoat = async (req: Request, res: Response) => { if (!(checkBoatName === null)) { return res - .status(404) + .status(400) .json({ success: false, error: "boatNameAlreadyExists" }); } } + //check if minP is bigger than maxP => error + if ( + !(newBoatInput.minP === undefined) && + !(newBoatInput.maxP === undefined) + ) { + if (newBoatInput.minP > newBoatInput.maxP) { + return res.status(409).json({ + success: false, + error: "maximumNumberOfSeatsMustBeBiggerOrEqualMinimalNumberOfSeats", + }); + } + } + //check if given sport-ids can be found const sportsArray = newBoatInput.sports; var check = true; diff --git a/server/src/controllers/createLogEntry.controllers.ts b/server/src/controllers/createLogEntry.controllers.ts index b16a20d..db84351 100644 --- a/server/src/controllers/createLogEntry.controllers.ts +++ b/server/src/controllers/createLogEntry.controllers.ts @@ -33,7 +33,7 @@ const createLogEntryController = async (req: Request, res: Response) => { if (numOfAdditionalClients !== numP - 1) { //-1 because of the responsible Person - return res.status(404).json({ + return res.status(409).json({ success: false, error: "numberOfAllGivenClientsNamesDoesNotMatchNumberOfAllClients", }); @@ -44,7 +44,7 @@ const createLogEntryController = async (req: Request, res: Response) => { const maxP = chosenBoat.maxP; if (!(logEntryInput.numP >= minP && logEntryInput.numP <= maxP)) { - return res.status(404).json({ + return res.status(409).json({ success: false, error: "numberOfAllGivenClientsDoesNotMatchRequirementsOfChosenBoatSeatNumber", @@ -58,6 +58,7 @@ const createLogEntryController = async (req: Request, res: Response) => { return res.status(201).json({ success: true, result: { + id: newLogEntry.id, startTime: newLogEntry.startTime, estimatedEndTime: newLogEntry.estimatedEndTime, email: newLogEntry.email, diff --git a/server/src/controllers/user.controllers.ts b/server/src/controllers/user.controllers.ts index cea3237..5de4597 100644 --- a/server/src/controllers/user.controllers.ts +++ b/server/src/controllers/user.controllers.ts @@ -48,6 +48,24 @@ const updateCurrentUser = async (req: Request, res: Response) => { .json({ success: true, result: {}, message: "noInputFound" }); } + if (input.first_name !== undefined && input.first_name.length >= 30) { + return res.status(400).json({ + success: false, + result: { + first_name: "Please provide maximum 30 character or empty string", + }, + }); + } + + if (input.last_name !== undefined && input.last_name.length >= 30) { + return res.status(400).json({ + success: false, + result: { + last_name: "Please provide maximum 30 character or empty string", + }, + }); + } + if (input.password !== undefined) { input.password = await bcrypt.hash(input.password, 10); } -- GitLab