feat: Add the /api/user/score endpoint

This commit is contained in:
Alexander Polynomdivision 2018-09-29 22:09:49 +02:00
parent 8a9094c41e
commit 076d6c8233
2 changed files with 30 additions and 2 deletions

View File

@ -14,8 +14,9 @@
correct: number,
wrong: number,
},
lastLevel: string,
lastLevel: number,
levels: number[],
queue: number[],
}

View File

@ -191,6 +191,7 @@ userRouter.post("/level/:id", async (req: LRequest, res) => {
levels: user.levels.concat(id),
};
if (id > Math.max(...user.levels)) {
// TODO: Add the levels vocabulary to the users review queue
// Also update the lastLevel attribute
Object.assign(update, { lastLevel: id });
}
@ -279,4 +280,30 @@ userRouter.post("/showWelcome", async (req: LRequest, res) => {
});
});
userRouter.post("/score", async (req: LRequest, res) => {
const { token, db } = req;
// Are all arguments specified
if (!req.body || !("score" in req.body)) {
res.send({
error: "400",
data: {
msg: "No score specified!",
},
});
return;
}
// TODO: if (user)
const user = await userFromSession(token, db);
// Update the score
db.collection("users").updateOne({
username: user.username,
}, {
$set: {
score: req.body.score,
},
});
});
export default userRouter;