From 71458067d80cc572aa829ee4b6641b779da461a6 Mon Sep 17 00:00:00 2001 From: Bastian Wagner Date: Sun, 8 Sep 2024 14:21:33 +0200 Subject: [PATCH] fix logs --- idp/src/application/user/user.service.ts | 31 ++++++++++++------------ 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/idp/src/application/user/user.service.ts b/idp/src/application/user/user.service.ts index 1d9c7bf..41885f8 100644 --- a/idp/src/application/user/user.service.ts +++ b/idp/src/application/user/user.service.ts @@ -34,22 +34,23 @@ export class UserService { systemLogins: 0, }; - const current = first; - while (current <= last) { - current.setDate(current.getDate() + 1); - res[current.toISOString().substring(0, 10)] = { - logins: 0, - systemLogins: 0, - }; - } - - logs.forEach((l) => { - if (l.type == 'login') { - res[l.timestamp.toISOString().substring(0, 10)].logins += 1; - } else if (l.type == 'systemlogin') { - res[l.timestamp.toISOString().substring(0, 10)].systemLogins += 1; + if (logs.length > 1) { + const current = first; + while (current <= last) { + current.setDate(current.getDate() + 1); + res[current.toISOString().substring(0, 10)] = { + logins: 0, + systemLogins: 0, + }; } - }); + logs.forEach((l) => { + if (l.type == 'login') { + res[l.timestamp.toISOString().substring(0, 10)].logins += 1; + } else if (l.type == 'systemlogin') { + res[l.timestamp.toISOString().substring(0, 10)].systemLogins += 1; + } + }); + } return Object.entries(res).map(([date, count]) => ({ date: new Date(date),