feat: Implement the /user/vocab endpoint

This commit is contained in:
Alexander Polynomdivision 2018-10-11 14:25:46 +02:00
parent 8e3919a70e
commit 528c291b70
2 changed files with 36 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "lateinicusserver", "name": "lateinicusserver",
"version": "1.1.0", "version": "1.2.0",
"description": "The backend server for Lateinicus", "description": "The backend server for Lateinicus",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {

View File

@ -58,6 +58,41 @@ userRouter.get("/logout", async (req: LRequest, res) => {
}); });
}); });
userRouter.get("/vocab", async (req: LRequest, res) => {
// Get the user
const { db, token } = req;
// TODO: if (!user)
const user = await userFromSession(token, db);
const { vocabMetadata } = await db.collection("users").findOne({
username: user.username,
});
if (!vocabMetadata) {
res.send({
error: "500",
data: {
msg: "Failed to retrieve Review Queue",
},
});
return;
}
const vocabIds = Object.keys(vocabMetadata).map(id => parseInt(id));
// Extract the vocabulary items
// TODO: Errorhandling
const vocab = await db.collection("vocabulary").find({
id: {
$in: vocabIds,
},
}).toArray();
res.send({
error: "200",
data: vocab,
});
});
// TODO: This should be shared with the frontend, to remove code duplication // TODO: This should be shared with the frontend, to remove code duplication
export enum VocabType { export enum VocabType {
NOMEN = 0, NOMEN = 0,