feat: Add the /api/user/score endpoint
This commit is contained in:
parent
8a9094c41e
commit
076d6c8233
@ -14,8 +14,9 @@
|
||||
correct: number,
|
||||
wrong: number,
|
||||
},
|
||||
|
||||
lastLevel: string,
|
||||
|
||||
lastLevel: number,
|
||||
levels: number[],
|
||||
|
||||
queue: number[],
|
||||
}
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user