Skip to content
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

Merged
merged 2 commits into from
May 19, 2024

Conversation

Hemu21
Copy link
Contributor

@Hemu21 Hemu21 commented May 18, 2024

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 apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (Documentation content changed)
  • Other (please describe):

Checklist

Put an x in the boxes that apply

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • My changes does not break the current system and it passes all the current test cases.

Screenshots or video

kajolcheck.mp4


}

const result = await teamMemberModel.findByIdAndDelete(memberId);

Check failure

Code scanning / CodeQL

Database query built from user-controlled sources High

This query object depends on a
user-provided value
.
@Hemu21
Copy link
Contributor Author

Hemu21 commented May 18, 2024

@Kajol-Kumari can you please check and merge it.

Copy link
Member

@Kajol-Kumari Kajol-Kumari left a 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);
Copy link
Member

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);
Copy link
Member

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' });

Copy link
Contributor Author

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 Kajol-Kumari added level2 Bug fixing, adding small features. gssoc GSSoC'24 Label labels May 19, 2024
@Hemu21
Copy link
Contributor Author

Hemu21 commented May 19, 2024

@Kajol-Kumari updated can you please check it.

Copy link
Member

@Kajol-Kumari Kajol-Kumari left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@Kajol-Kumari Kajol-Kumari merged commit 02e2e09 into HITK-TECH-Community:main May 19, 2024
6 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gssoc GSSoC'24 Label level2 Bug fixing, adding small features.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Backend] The DELETE teamMemebers API should also delete the respective file stored in the disk
2 participants