From 85367e844d20b27a239ba150fe400561118f7c05 Mon Sep 17 00:00:00 2001 From: Artem Anufrij Date: Tue, 19 Sep 2023 15:00:25 +0200 Subject: [PATCH] api for deleting progress --- router/user.js | 35 +++++++++++++++++++---------------- services/database/progress.js | 2 +- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/router/user.js b/router/user.js index 37ebb7f..fb266f7 100644 --- a/router/user.js +++ b/router/user.js @@ -136,21 +136,6 @@ router }); }); -router - .route("/progress") - .post(passport.authenticate("jwt", { session: false }), (req, res) => { - let item = req.body; - item.userId = req.user._id; - database.progress.update(item); - res.status(200).end(); - }) - .delete(passport.authenticate("jwt", { session: false }), (req, res) => { - let item = req.body; - item.userId = req.user._id; - database.progress.delete(item); - res.status(200).end(); - }); - router .route("/history") .post(passport.authenticate("jwt", { session: false }), (req, res) => { @@ -169,12 +154,30 @@ router }); }); -router.route("/progress/:parent") +router + .route("/progress") + .post(passport.authenticate("jwt", { session: false }), (req, res) => { + let item = req.body; + item.userId = req.user._id; + database.progress.update(item); + res.status(200).end(); + }); + +router + .route("/progress/:parent") .get(passport.authenticate("jwt", { session: false }), (req, res) => { database.progress.get(req.params.parent, result => { res.json(result).end(); }); }) + .delete(passport.authenticate("jwt", { session: false }), (req, res) => { + let item = { + parentId: req.params.parent, + userId: req.user._id + } + database.progress.delete(item); + res.status(200).end(); + }); router .route("/settings") diff --git a/services/database/progress.js b/services/database/progress.js index 704e7c3..27ce169 100644 --- a/services/database/progress.js +++ b/services/database/progress.js @@ -21,7 +21,7 @@ exports.update = function (item) { }; exports.delete = function (item) { - dbo.collection("progress").deleteMany({ userId: ObjectId(item.userId), id: item.id }, (err) => { + dbo.collection("progress").deleteMany({ userId: ObjectId(item.userId), parentId: item.parentId }, (err) => { if (err) throw err; }); } \ No newline at end of file