This commit is contained in:
lingdocs 2022-09-08 11:49:10 +04:00
parent 63e2d01feb
commit 0a9e5e274f
1 changed files with 13 additions and 8 deletions

View File

@ -154,14 +154,7 @@ const authRouter = (passport: PassportStatic) => {
const users = (await getAllLingdocsUsers()).sort((a, b) => (
(a.accountCreated || 0) - (b.accountCreated || 0)
));
const tests: { id: string, passes: number }[] = [];
users.forEach(u => (
u.tests.forEach(({id}) => {
const ti = tests.findIndex(x => x.id === id);
if (ti > -1) tests[ti].passes++;
else tests.push({ id, passes: 0 });
})
));
const tests = getTestCompletionSummary(users)
res.render("admin", { users, tests });
} catch (e) {
next(e);
@ -310,4 +303,16 @@ const authRouter = (passport: PassportStatic) => {
return router;
}
function getTestCompletionSummary(users: T.LingdocsUser[]) {
const tests: { id: string, passes: number }[] = [];
users.forEach(u => (
u.tests.forEach(({id}) => {
const ti = tests.findIndex(x => x.id === id);
if (ti > -1) tests[ti].passes++;
else tests.push({ id, passes: 1 });
})
));
return tests;
}
export default authRouter;