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

check for boattype duplicates

parent 39d70c1b
No related branches found
No related tags found
No related merge requests found
......@@ -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) {
......
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