-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
ISSUE_NUMBER: GH-18
Description
The createChapter function in controllers/chapterController.js creates new topics without checking for existing topics with the same name, potentially leading to duplicates.
File: repositories/QuestionBankapi/controllers/chapterController.js
Line: 35-40
Severity: medium
Current Behavior
The code iterates through a list of topic names and creates a new Topic document for each name without checking if a topic with that name already exists for the given subject, chapter, and standard.
Expected Behavior
The code should check if a topic with the same name already exists before creating a new one.
Suggested Fix
Add a check to see if a topic with the same name already exists before creating a new topic.
Code Context
if (Array.isArray(topics)) {
for (const topicName of topics) {
const newTopic = new Topic({ name: topicName, subjectName: name, chapterName, standard });
await newTopic.save();
newChapter.topics.push(newTopic._id);
}Additional Notes
This could lead to data redundancy and inconsistencies in the database.
Reactions are currently unavailable