From 0f8d795b80973416028f73c8da80fe8b01734dea Mon Sep 17 00:00:00 2001 From: Ankit <115006624+ANKIT638-ux@users.noreply.github.com> Date: Sun, 24 Dec 2023 11:03:36 +0530 Subject: [PATCH] Validation for organization --- controller/organization.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/controller/organization.js b/controller/organization.js index b89c921..7e3793f 100644 --- a/controller/organization.js +++ b/controller/organization.js @@ -5,10 +5,20 @@ import { getOrganizations, } from "#services/organization"; import { logger } from "#util"; +import { isEntityIdValid } from "#middleware/entityIdValidation"; +import Accreditation from "#models/accreditation"; +import Parent from "#models/organization"; async function addOrganization(req, res) { const { parent, startDate, name, accreditation } = req.body; + const isAccreditationValid = await isEntityIdValid(accreditation, Accreditation); + const isParentValid = await isEntityIdValid(parent, Parent); try { + if (!isAccreditationValid || !isParentValid) { + res.status(400).json({ + error: "Invalid Id", + }); + } const organization = await addNewOrganization( parent, startDate,