From 0a9e5e274fcc96543a8c8884c64e9b156a3b8a97 Mon Sep 17 00:00:00 2001 From: lingdocs <71590811+lingdocs@users.noreply.github.com> Date: Thu, 8 Sep 2022 11:49:10 +0400 Subject: [PATCH] oops --- account/src/routers/auth-router.ts | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/account/src/routers/auth-router.ts b/account/src/routers/auth-router.ts index fc29397..1afe0a5 100644 --- a/account/src/routers/auth-router.ts +++ b/account/src/routers/auth-router.ts @@ -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; \ No newline at end of file