refactor: topic model function

This commit is contained in:
elangptra 2024-10-02 14:04:17 +07:00
parent 8007844fa8
commit 0d22b6b38b

View File

@ -32,9 +32,9 @@ export const getTopicBySectionId = async (req, res) => {
const { sectionId } = req.params; const { sectionId } = req.params;
const sectionExists = await models.Section.findByPk(sectionId); const sectionExists = await models.Section.findByPk(sectionId);
if (!sectionExists) { // if (!sectionExists) {
return response(404, null, "Section not found", res); // return response(404, null, "Section not found", res);
} // }
const topics = await models.Topic.findAll({ const topics = await models.Topic.findAll({
where: { ID_SECTION: sectionId }, where: { ID_SECTION: sectionId },
@ -167,6 +167,7 @@ export const getCompletedTopicsBySection = async (req, res) => {
"ID_SECTION", "ID_SECTION",
"NAME_SECTION", "NAME_SECTION",
"DESCRIPTION_SECTION", "DESCRIPTION_SECTION",
"THUMBNAIL",
], ],
}, },
], ],
@ -204,6 +205,7 @@ export const getCompletedTopicsBySection = async (req, res) => {
ID_SECTION: section.ID_SECTION, ID_SECTION: section.ID_SECTION,
NAME_SECTION: section.NAME_SECTION, NAME_SECTION: section.NAME_SECTION,
DESCRIPTION_SECTION: section.DESCRIPTION_SECTION, DESCRIPTION_SECTION: section.DESCRIPTION_SECTION,
THUMBNAIL: section.THUMBNAIL,
TOTAL_TOPICS: totalTopicsInSection, TOTAL_TOPICS: totalTopicsInSection,
COMPLETED_TOPICS: 0, COMPLETED_TOPICS: 0,
}; };