Skip to content

Commit aabfee3

Browse files
Merge pull request #441 from tcet-opensource/425-add-validation-for-group
[Added]validation for group
2 parents 22235ee + b5767ec commit aabfee3

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

controller/group.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,20 @@ import {
55
updateGroupById,
66
} from "#services/group";
77
import { logger } from "#util";
8+
import { isEntityIdValid } from "#middleware/entityIdValidation";
9+
import Student from '#models/student';
810

911
async function addGroup(req, res) {
1012
const { title, student } = req.body;
13+
const isStudentValid = await isEntityIdValid(student, Student);
1114
try {
15+
if(isStudentValid){
1216
const group = await createGroup(title, student);
1317
res.json({ res: `added group ${group.id}`, id: group.id });
18+
}
19+
else{
20+
res.status(400).json({err: "Invalid Id"});
21+
}
1422
} catch (error) {
1523
logger.error("Error while inserting", error);
1624
res.status(500);

0 commit comments

Comments
 (0)