refactor: section update

This commit is contained in:
elangptra 2024-12-12 18:01:24 +07:00
parent 405e7a508c
commit f23cf5c93a
4 changed files with 20 additions and 3 deletions

View File

@ -192,7 +192,7 @@ export const updateSectionById = async (req, res) => {
if (NAME_SECTION && NAME_SECTION !== section.NAME_SECTION) { if (NAME_SECTION && NAME_SECTION !== section.NAME_SECTION) {
const existingSection = await models.Section.findOne({ const existingSection = await models.Section.findOne({
where: { NAME_SECTION }, where: { NAME_SECTION, IS_DELETED: 0 },
transaction, transaction,
}); });

View File

@ -110,7 +110,7 @@ export const getTopicForAdmin = async (req, res) => {
DESCRIPTION_TOPIC: { DESCRIPTION_TOPIC: {
[models.Op.like]: `%${search}%`, [models.Op.like]: `%${search}%`,
}, },
} },
], ],
}), }),
}, },
@ -204,7 +204,7 @@ export const createTopic = async (req, res) => {
return response( return response(
409, 409,
null, null,
"Topic with the same name already exists", "Topic with the same name already exists in this section",
res res
); );
} }
@ -268,6 +268,23 @@ export const updateTopicById = async (req, res) => {
} }
if (NAME_TOPIC) { 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; topic.NAME_TOPIC = NAME_TOPIC;
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 87 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB