save-and-restore-progress-for-audio fix #12 #14

Merged
artem merged 2 commits from save-and-restore-progress-for-audio into main 2023-09-19 16:34:09 +02:00
2 changed files with 20 additions and 17 deletions
Showing only changes of commit 85367e844d - Show all commits

View File

@ -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 router
.route("/history") .route("/history")
.post(passport.authenticate("jwt", { session: false }), (req, res) => { .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) => { .get(passport.authenticate("jwt", { session: false }), (req, res) => {
database.progress.get(req.params.parent, result => { database.progress.get(req.params.parent, result => {
res.json(result).end(); 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 router
.route("/settings") .route("/settings")

View File

@ -21,7 +21,7 @@ exports.update = function (item) {
}; };
exports.delete = 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; if (err) throw err;
}); });
} }