diff --git a/controllers/contentControllers/section.js b/controllers/contentControllers/section.js index 8ac8540..ac032b4 100644 --- a/controllers/contentControllers/section.js +++ b/controllers/contentControllers/section.js @@ -192,7 +192,7 @@ export const updateSectionById = async (req, res) => { if (NAME_SECTION && NAME_SECTION !== section.NAME_SECTION) { const existingSection = await models.Section.findOne({ - where: { NAME_SECTION }, + where: { NAME_SECTION, IS_DELETED: 0 }, transaction, }); diff --git a/controllers/contentControllers/topic.js b/controllers/contentControllers/topic.js index 313508d..a628351 100644 --- a/controllers/contentControllers/topic.js +++ b/controllers/contentControllers/topic.js @@ -110,7 +110,7 @@ export const getTopicForAdmin = async (req, res) => { DESCRIPTION_TOPIC: { [models.Op.like]: `%${search}%`, }, - } + }, ], }), }, @@ -204,7 +204,7 @@ export const createTopic = async (req, res) => { return response( 409, null, - "Topic with the same name already exists", + "Topic with the same name already exists in this section", res ); } @@ -268,6 +268,23 @@ export const updateTopicById = async (req, res) => { } if (NAME_TOPIC) { + const existingTopic = await models.Topic.findOne({ + where: { + ID_SECTION: ID_SECTION || topic.ID_SECTION, + NAME_TOPIC, + IS_DELETED: 0, + }, + }); + + if (existingTopic && existingTopic.ID_TOPIC !== topic.ID_TOPIC) { + return response( + 409, + null, + "Topic with the same name already exists in this section", + res + ); + } + topic.NAME_TOPIC = NAME_TOPIC; } diff --git a/media/uploads/section/THUMBNAIL-50793054-a549-455e-ac5a-f08e1c357df3-3b4db19865d8b70386db0834852659ac.jpeg b/media/uploads/section/THUMBNAIL-50793054-a549-455e-ac5a-f08e1c357df3-3b4db19865d8b70386db0834852659ac.jpeg new file mode 100644 index 0000000..39859e4 Binary files /dev/null and b/media/uploads/section/THUMBNAIL-50793054-a549-455e-ac5a-f08e1c357df3-3b4db19865d8b70386db0834852659ac.jpeg differ diff --git a/media/uploads/section/THUMBNAIL-e2a21f70-217f-4d08-a7a2-cbaa568a450e-81346cbd4317524acfd617bf14c006ce.jpeg b/media/uploads/section/THUMBNAIL-e2a21f70-217f-4d08-a7a2-cbaa568a450e-81346cbd4317524acfd617bf14c006ce.jpeg new file mode 100644 index 0000000..953f28d Binary files /dev/null and b/media/uploads/section/THUMBNAIL-e2a21f70-217f-4d08-a7a2-cbaa568a450e-81346cbd4317524acfd617bf14c006ce.jpeg differ