-
Notifications
You must be signed in to change notification settings - Fork 0
Description
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.