fix: Cleanup the /queue route a bit
This commit is contained in:
parent
f22008784c
commit
16bf39f691
@ -107,8 +107,17 @@ userRouter.get("/queue", async (req: LRequest, res) => {
|
||||
const { token, db } = req;
|
||||
let user = Object.assign({}, await userFromSession(token, db));
|
||||
|
||||
// We want to add the id of the vocabulary that the metadata belongs to
|
||||
// to the metadata object, so that we can identify the original vocabulary
|
||||
// item later on.
|
||||
const sm2 = user.vocabMetadata;
|
||||
const data = Object.keys(sm2).map(id => Object.assign({}, sm2[parseInt(id)], { id, }));
|
||||
const assignId = (id_str: string) => {
|
||||
const id = parseInt(id_str);
|
||||
return Object.assign({}, sm2[id], { id, });
|
||||
};
|
||||
const data = Object.keys(sm2).map(assignId);
|
||||
|
||||
// Sort the vocabulary based on the next due date...
|
||||
const sorted = data.sort((a: any, b: any) => {
|
||||
if (a.nextDueDate > b.nextDueDate)
|
||||
return 1;
|
||||
@ -116,7 +125,9 @@ userRouter.get("/queue", async (req: LRequest, res) => {
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}).slice(0, 20)
|
||||
})
|
||||
// ...and return 20 at max.
|
||||
.slice(0, 20)
|
||||
.map((el: any) => {
|
||||
return parseInt(el.id);
|
||||
});
|
||||
|
Reference in New Issue
Block a user