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

**For Now User Profile is done** #4

Merged
merged 1 commit into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 30 additions & 3 deletions src/controllers/profile.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,16 +209,43 @@ const deleteProfile = asynchandler(async (req, res) => {
throw new ApiError(400, 'User not found!!');
}

const deletedUser = await findByIdAndDelete(userId);
// Aggregate to find the user details
const userToDelete = await User.aggregate([
{
$match: {
_id: userId,
},
},
{
$project: {
_id: 1,
username: 1,
fullName: 1,
phoneNumber: 1,
},
},
]);

// Check if user exists
if (userToDelete.length === 0) {
throw new ApiError(404, 'User not found!!');
}

// Delete the user
const deletedUser = await User.findByIdAndDelete(userId);
if (!deletedUser) {
throw new ApiError(400, "User can't be able to deelte!!!");
throw new ApiError(400, "User can't be deleted!!!");
}

return res
.status(200)
.json(new ApiResponse(200, 'User Deleted Successfully!!!'), deletedUser);
.json(
new ApiResponse(200, 'User Deleted Successfully!!!', userToDelete[0])
);
});



export {
addProfilePicture,
updateProfile,
Expand Down
2 changes: 1 addition & 1 deletion src/routes/profile.route.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@

router.route("/profile/deleteProfile").delete(
verifyJwt,
checkRole('admin'),
checkRole(['customer']),
deleteProfile

Check failure

Code scanning / CodeQL

Missing rate limiting High

This route handler performs
a database access
, but is not rate-limited.
)

router
Expand Down
Loading