This commit is contained in:
Bastian Wagner
2024-09-08 14:17:27 +02:00
parent 512160799e
commit 2a936bb4b5
5 changed files with 29 additions and 39 deletions

View File

@@ -8,8 +8,7 @@ export class UserService {
constructor(
private clientRepository: ClientRepository,
private logRepository: LogRepository,
) {
}
) {}
getUserClients(user: User): Promise<Client[]> {
return this.clientRepository.find({
@@ -22,21 +21,35 @@ export class UserService {
async getUserLogins() {
const logs = await this.logRepository.find({
where: [{ type: 'login' }, { type: 'systemlogin' }],
order: { timestamp: 'asc' },
});
const res = logs.reduce((acc, succ) => {
let ob = acc[succ.timestamp.toISOString().substring(0, 10)];
if (!ob) {
ob = { logins: 0, systemLogins: 0 };
const first = logs[0].timestamp;
const last = logs[logs.length - 1].timestamp;
const res = {};
res[first.toISOString().substring(0, 10)] = {
logins: 0,
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 (succ.type == 'login') {
ob.logins += 1;
} else if (succ.type == 'systemlogin') {
ob.systemLogins += 1;
}
acc[succ.timestamp.toISOString().substring(0, 10)] = ob;
return acc;
}, {});
});
return Object.entries(res).map(([date, count]) => ({
date: new Date(date),

View File

@@ -6,8 +6,8 @@ import Chart from 'chart.js/auto';
selector: 'app-chart-login',
standalone: true,
imports: [],
templateUrl: './login.component.html',
styleUrl: './login.component.scss'
templateUrl: './login.chart.component.html',
styleUrl: './login.chart.component.scss'
})
export class LoginChartComponent {
chart: any = [];

View File

@@ -1,23 +0,0 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { LoginComponent } from './login.component';
describe('LoginComponent', () => {
let component: LoginComponent;
let fixture: ComponentFixture<LoginComponent>;
beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LoginComponent]
})
.compileComponents();
fixture = TestBed.createComponent(LoginComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});