Skip to content

Commit

Permalink
Merge pull request #4 from beingPro007/developement
Browse files Browse the repository at this point in the history
**For Now User Profile is done**
  • Loading branch information
beingPro007 authored Oct 11, 2024
2 parents 084bd8d + bfd0dd5 commit 1627f1e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
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,7 +45,7 @@ router.route("/profile/addAdress").post(

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

Expand Down

0 comments on commit 1627f1e

Please sign in to comment.