-
Notifications
You must be signed in to change notification settings - Fork 317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Backend] The DELETE teamMemebers API should also delete the respective file stored in the disk Fixed #930
Conversation
@Kajol-Kumari can you please check and merge it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Hemu21 can you please address the requested changes?
catch(error) { | ||
return res.status(500).json({error:"Some internal server error"}); | ||
|
||
const member = await teamMemberModel.findById(memberId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why so we need to make an extra db call here? can we use the result
?
|
||
} | ||
|
||
const result = await teamMemberModel.findByIdAndDelete(memberId); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This result should have the detail of delete object, can't we do like below? -
const result = await teamMemberModel.findByIdAndDelete(memberId);
if (!result) {
return res.status(401).json({ error: 'Invalid id' });
}
const fileName = path.basename(result.image);
const imagePath = path.join(__dirname, '../../../uploads/teamMembersProfile/', fileName);
fs.unlink(imagePath, (err) => {
if (err) {
console.error('Failed to delete image file:', err);
}
console.log('Image file deleted:', imagePath);
});
return res.status(200).json({ message: 'Team member deleted successfully' });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Kajol-Kumari thank you. I forget that delete has the deleted object. so I make extra. Now i updated it.
@Kajol-Kumari updated can you please check it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
Issue that this pull request solves
Issue Link resolve #916
Closes: #916
Brief description of what is fixed or changed
The delete call should also delete the image file before deleting the data form the DB. added in the delete function.
Types of changes
Put an
x
in the boxes that applyChecklist
Put an
x
in the boxes that applyScreenshots or video
kajolcheck.mp4