refactor: unique class name
This commit is contained in:
parent
cbde854051
commit
405e7a508c
|
|
@ -129,6 +129,14 @@ export const createClass = async (req, res) => {
|
|||
}
|
||||
|
||||
try {
|
||||
const existingClass = await models.Class.findOne({
|
||||
where: { NAME_CLASS },
|
||||
});
|
||||
|
||||
if (existingClass) {
|
||||
return response(400, null, "Class with this name already exists", res);
|
||||
}
|
||||
|
||||
const newClass = await models.Class.create({
|
||||
NAME_CLASS,
|
||||
TOTAL_STUDENT,
|
||||
|
|
@ -152,8 +160,21 @@ export const updateClassById = async (req, res) => {
|
|||
return response(404, null, "Class not found", res);
|
||||
}
|
||||
|
||||
if (NAME_CLASS) classes.NAME_CLASS = NAME_CLASS;
|
||||
if (TOTAL_STUDENT) classes.TOTAL_STUDENT = TOTAL_STUDENT;
|
||||
if (NAME_CLASS && NAME_CLASS !== classes.NAME_CLASS) {
|
||||
const existingClass = await models.Class.findOne({
|
||||
where: { NAME_CLASS },
|
||||
});
|
||||
|
||||
if (existingClass) {
|
||||
return response(400, null, "Class with this name already exists", res);
|
||||
}
|
||||
|
||||
classes.NAME_CLASS = NAME_CLASS;
|
||||
}
|
||||
|
||||
if (TOTAL_STUDENT) {
|
||||
classes.TOTAL_STUDENT = TOTAL_STUDENT;
|
||||
}
|
||||
|
||||
await classes.save();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user