Skip to content

Commit 25a5cdd

Browse files
author
bgonzalez
committed
Se agrego el delete (solo cambia el ective a false)
1 parent dee8119 commit 25a5cdd

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

controller/user.controller.js

+19-6
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ const post_user = async (req = request, res = response) => {
9696
* `json()` which is used to send a JSON response.
9797
*/
9898
const put_user = async (req = request, res = response) => {
99-
const { id } = req.params;
99+
const { id } = req.query;
100100
const { _id, password, google, email, ...user_param } = req.body;
101101

102102
// encrypyt password
@@ -140,11 +140,24 @@ const put_user = async (req = request, res = response) => {
140140
* the client. It contains methods and properties that allow you to control the response, such as
141141
* `json()` which is used to send a JSON response.
142142
*/
143-
const delete_user = (req = request, res = response) => {
144-
res.json({
145-
message: 'DELETE - USER SUCCESS',
146-
data: {}
147-
});
143+
const delete_user = async (req = request, res = response) => {
144+
try {
145+
const { id } = req.params;
146+
// await user_model.deleteOne({ _id: id });
147+
const deleted_user = await user_model.findByIdAndUpdate(id, { active: false });
148+
await deleted_user.save();
149+
log(deleted_user);
150+
res.json({
151+
message: 'DELETE - USER SUCCESS',
152+
data: `User ${id} deleted successfully`
153+
});
154+
} catch (e) {
155+
res.status(500).json({
156+
message: 'DELETE - USER ERROR',
157+
data: {},
158+
error: e
159+
});
160+
}
148161
}
149162
/**
150163
* Handles a PATCH request for updating a user

routes/user.routes.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ user_router.post('/post', [
4040
validate_fields
4141
],post_user);
4242
// delete
43-
user_router.delete('/delete', delete_user);
43+
user_router.delete('/delete/:id', [
44+
check('id', 'Invalid id').isMongoId(),
45+
check('id').custom(validate_user_id)
46+
], delete_user);
4447
// patch
4548
user_router.patch('/patch', patch_user);
4649

0 commit comments

Comments
 (0)