diff --git a/server/src/controllers/boat.controllers.ts b/server/src/controllers/boat.controllers.ts index 64234393699e2cb19708c13e44b6e844b433700d..e5b85041336993b44ef1cee1e937a3bcbc4371e0 100644 --- a/server/src/controllers/boat.controllers.ts +++ b/server/src/controllers/boat.controllers.ts @@ -267,6 +267,28 @@ const updateBoatById = async (req: Request, res: Response) => { } } + //check if minP is bigger than maxP => error + if (!(input.minP === undefined) || !(input.maxP === undefined)) { + //compare only when the two values are given (minP AND maxP) + if (!(input.minP === undefined) && !(input.maxP === undefined)) { + if (input.maxP < input.minP) { + return res.status(409).json({ + success: false, + error: + "maximumNumberOfSeatsMustBeBiggerOrEqualMinimalNumberOfSeats", + }); + } + } + + //if only one entry is given for updated(minP OR maxP) we compare them with the values of minP and maxP already assigned to Boat. + if (input.minP > foundBoat.maxP || input.maxP < foundBoat.minP) { + return res.status(409).json({ + success: false, + error: "maximumNumberOfSeatsMustBeBiggerOrEqualMinimalNumberOfSeats", + }); + } + } + //try to update the attributes, which are in Boat table const updatedBoat = await Boat.update(input, { where: {