ISSUE_NUMBER: GH-33
Description
The deleteQuestion function in controllers/quesController.js uses forEach with async/await to delete images associated with question options. This approach doesn't guarantee that all images are deleted before the function proceeds, potentially leading to issues with resource cleanup or rate limits.
File: repositories/QuestionBankapi/controllers/quesController.js
Line: 128-132
Severity: medium
Current Behavior
The forEach loop doesn't wait for each image deletion to complete before moving to the next iteration.
Expected Behavior
All images should be deleted before the function proceeds to delete the question and update the user.
Suggested Fix
Replace forEach with Promise.all to ensure all image deletions are completed before proceeding.
Code Context
question.options.forEach(async (option) => {
if (option.images && option.images.length > 0) {
await deleteImages(option.images);
}
});
Additional Notes
Using Promise.all ensures proper resource cleanup and avoids potential issues with rate limits on the image deletion service.
ISSUE_NUMBER: GH-33
Description
The
deleteQuestionfunction incontrollers/quesController.jsusesforEachwithasync/awaitto delete images associated with question options. This approach doesn't guarantee that all images are deleted before the function proceeds, potentially leading to issues with resource cleanup or rate limits.File:
repositories/QuestionBankapi/controllers/quesController.jsLine: 128-132
Severity: medium
Current Behavior
The
forEachloop doesn't wait for each image deletion to complete before moving to the next iteration.Expected Behavior
All images should be deleted before the function proceeds to delete the question and update the user.
Suggested Fix
Replace
forEachwithPromise.allto ensure all image deletions are completed before proceeding.Code Context
Additional Notes
Using
Promise.allensures proper resource cleanup and avoids potential issues with rate limits on the image deletion service.