Skip to content
Snippets Groups Projects
Commit bb13fb92 authored by elit04's avatar elit04
Browse files

check if minP is bigger than maxP then error in update boat controller

parent d2a132e8
No related branches found
No related tags found
No related merge requests found
...@@ -267,6 +267,28 @@ const updateBoatById = async (req: Request, res: Response) => { ...@@ -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 //try to update the attributes, which are in Boat table
const updatedBoat = await Boat.update(input, { const updatedBoat = await Boat.update(input, {
where: { where: {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment