diff --git a/server/src/controllers/boatType.controllers.ts b/server/src/controllers/boatType.controllers.ts index d589a24ca7a502606d1718c288362d27c1a00405..a139d9fa7ceaa35826ca29a402ecae3eea1a1729 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) {