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