From 076d6c82339ca5544892fb5958c915bf4fa8dd17 Mon Sep 17 00:00:00 2001 From: Alexander Polynomdivision Date: Sat, 29 Sep 2018 22:09:49 +0200 Subject: [PATCH] feat: Add the /api/user/score endpoint --- backend/db.md | 5 +++-- backend/src/api/user.ts | 27 +++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/backend/db.md b/backend/db.md index afb7d97..0809de3 100644 --- a/backend/db.md +++ b/backend/db.md @@ -14,8 +14,9 @@ correct: number, wrong: number, }, - - lastLevel: string, + + lastLevel: number, + levels: number[], queue: number[], } diff --git a/backend/src/api/user.ts b/backend/src/api/user.ts index 9e20cbb..6028b1b 100644 --- a/backend/src/api/user.ts +++ b/backend/src/api/user.ts @@ -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;