Skip to content

Commit c8b25eb

Browse files
authored
Merge pull request #468 from tcet-opensource/428_Validation_for_organization
Validation for organization
2 parents e20ba34 + 0f8d795 commit c8b25eb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

controller/organization.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ import {
55
getOrganizations,
66
} from "#services/organization";
77
import { logger } from "#util";
8+
import { isEntityIdValid } from "#middleware/entityIdValidation";
9+
import Accreditation from "#models/accreditation";
10+
import Parent from "#models/organization";
811

912
async function addOrganization(req, res) {
1013
const { parent, startDate, name, accreditation } = req.body;
14+
const isAccreditationValid = await isEntityIdValid(accreditation, Accreditation);
15+
const isParentValid = await isEntityIdValid(parent, Parent);
1116
try {
17+
if (!isAccreditationValid || !isParentValid) {
18+
res.status(400).json({
19+
error: "Invalid Id",
20+
});
21+
}
1222
const organization = await addNewOrganization(
1323
parent,
1424
startDate,

0 commit comments

Comments
 (0)