feat: Implement the /user/vocab endpoint
This commit is contained in:
parent
8e3919a70e
commit
528c291b70
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lateinicusserver",
|
||||
"version": "1.1.0",
|
||||
"version": "1.2.0",
|
||||
"description": "The backend server for Lateinicus",
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
|
@ -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
|
||||
export enum VocabType {
|
||||
NOMEN = 0,
|
||||
|
Reference in New Issue
Block a user