Skip to content

Potential Duplicate Topic Creation in createChapter #81

@beetle-ai

Description

@beetle-ai

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions