From 7440ab115f13b76765cf9bc4f758e4d2386cd4b4 Mon Sep 17 00:00:00 2001 From: elit04 <elit04@fu-berlin.de> Date: Sun, 23 Jan 2022 06:40:40 -0500 Subject: [PATCH] check for boattype duplicates --- server/src/controllers/boatType.controllers.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/server/src/controllers/boatType.controllers.ts b/server/src/controllers/boatType.controllers.ts index d589a24..a139d9f 100644 --- a/server/src/controllers/boatType.controllers.ts +++ b/server/src/controllers/boatType.controllers.ts @@ -13,6 +13,17 @@ const createBoatTypeController = async (req: Request, res: Response) => { const newBoatTypeInput = req.body; + //check if BoatType already exists in DB to avoid duplicates + const findIfBoatTypeExists = await BoatType.findOne({ + where: { name: newBoatTypeInput.name }, + }); + + if (findIfBoatTypeExists) { + return res + .status(404) + .json({ success: false, error: "boatTypeAlreadyExists" }); + } + const newBoatType = await BoatType.create(newBoatTypeInput); if (newBoatType) { -- GitLab