Skip to content

Commit b600c66

Browse files
committed
[Modified] Added validation
1 parent 5ae14b8 commit b600c66

File tree

2 files changed

+23
-35
lines changed

2 files changed

+23
-35
lines changed

.husky/pre-commit

Lines changed: 0 additions & 13 deletions
This file was deleted.

controller/department.js

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Infrastructure from "#models/infrastructure";
1010
import Organization from "#models/organization";
1111
import { logger } from "#util";
1212

13+
1314
async function addDepartment(req, res) {
1415
const {
1516
name,
@@ -19,34 +20,34 @@ async function addDepartment(req, res) {
1920
infrastructures,
2021
organization,
2122
} = req.body;
22-
2323
const isAccredationValid = await isEntityIdValid(accreditations, Accreditation);
2424
const isInfrastructureValid = await isEntityIdValid(infrastructures, Infrastructure);
2525
const isOrganizationValid = await isEntityIdValid(organization, Organization);
2626

27+
2728
try {
28-
29+
2930
if (!isAccredationValid && !isInfrastructureValid && !isOrganizationValid) {
30-
31-
const error = "";
32-
if (!isBranchValid) error.concat("Invalid branch");
33-
if (!isCourseValid) error.concat(" Invalid course opted");
34-
res.status(400).json({ err: error });
35-
}
36-
else {
37-
const department = await createnewdepartment(
38-
name,
39-
acronym,
40-
yearOfStarting,
41-
accreditations,
42-
infrastructures,
43-
organization,
44-
);
45-
res.json({
46-
res: `added Department successfully ${department.name}`,
47-
id: department.id,
48-
});
49-
}
31+
32+
const error = "";
33+
if (!isBranchValid) error.concat("Invalid branch");
34+
if (!isCourseValid) error.concat(" Invalid course opted");
35+
res.status(400).json({ err: error });
36+
}
37+
else {
38+
const department = await createnewdepartment(
39+
name,
40+
acronym,
41+
yearOfStarting,
42+
accreditations,
43+
infrastructures,
44+
organization,
45+
);
46+
res.json({
47+
res: `added Department successfully ${department.name}`,
48+
id: department.id,
49+
});
50+
}
5051
} catch (error) {
5152
logger.error("Error while inserting", error);
5253
res.status(500);

0 commit comments

Comments
 (0)