From 4f133c55d20e24d2c4a7c3242b1a8d0d01ba66ed Mon Sep 17 00:00:00 2001 From: Alexander Polynomdivision Date: Sun, 30 Sep 2018 21:17:47 +0200 Subject: [PATCH] feat: Add new vocabulary to the review queue When a level is finished, the vocabulary of that item will be converted into SM2 metadata, which will be appended to the user's vocabMetadata. --- backend/src/api/user.ts | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/backend/src/api/user.ts b/backend/src/api/user.ts index ad16143..1f7311b 100644 --- a/backend/src/api/user.ts +++ b/backend/src/api/user.ts @@ -261,9 +261,27 @@ 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 + // TODO: if (!level) + const level = await db.collection("levels").findOne({ + level: id, + }); + + // Convert the level's vocabulary to SM2 metadata + let sm2: { [id: number]: ISM2Metadata } = {}; + level.vocab.forEach((id: number) => { + sm2[id] = { + easiness: 1.3, + consecutiveCorrectAnswers: 0, + nextDueDate: Date.parse((new Date()).toString()), + }; + }); + const newVocabMetadata = Object.assign({}, user.vocabMetadata, sm2); + // Also update the lastLevel attribute - Object.assign(update, { lastLevel: id }); + Object.assign(update, { + lastLevel: id, + vocabMetadata: newVocabMetadata, + }); } await db.collection("users").updateOne({ username: user.username,