logging
This commit is contained in:
@@ -8,8 +8,7 @@ export class UserService {
|
|||||||
constructor(
|
constructor(
|
||||||
private clientRepository: ClientRepository,
|
private clientRepository: ClientRepository,
|
||||||
private logRepository: LogRepository,
|
private logRepository: LogRepository,
|
||||||
) {
|
) {}
|
||||||
}
|
|
||||||
|
|
||||||
getUserClients(user: User): Promise<Client[]> {
|
getUserClients(user: User): Promise<Client[]> {
|
||||||
return this.clientRepository.find({
|
return this.clientRepository.find({
|
||||||
@@ -22,21 +21,35 @@ export class UserService {
|
|||||||
async getUserLogins() {
|
async getUserLogins() {
|
||||||
const logs = await this.logRepository.find({
|
const logs = await this.logRepository.find({
|
||||||
where: [{ type: 'login' }, { type: 'systemlogin' }],
|
where: [{ type: 'login' }, { type: 'systemlogin' }],
|
||||||
|
order: { timestamp: 'asc' },
|
||||||
});
|
});
|
||||||
|
|
||||||
const res = logs.reduce((acc, succ) => {
|
const first = logs[0].timestamp;
|
||||||
let ob = acc[succ.timestamp.toISOString().substring(0, 10)];
|
const last = logs[logs.length - 1].timestamp;
|
||||||
if (!ob) {
|
|
||||||
ob = { logins: 0, systemLogins: 0 };
|
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,
|
||||||
|
};
|
||||||
}
|
}
|
||||||
if (succ.type == 'login') {
|
|
||||||
ob.logins += 1;
|
logs.forEach((l) => {
|
||||||
} else if (succ.type == 'systemlogin') {
|
if (l.type == 'login') {
|
||||||
ob.systemLogins += 1;
|
res[l.timestamp.toISOString().substring(0, 10)].logins += 1;
|
||||||
|
} else if (l.type == 'systemlogin') {
|
||||||
|
res[l.timestamp.toISOString().substring(0, 10)].systemLogins += 1;
|
||||||
}
|
}
|
||||||
acc[succ.timestamp.toISOString().substring(0, 10)] = ob;
|
});
|
||||||
return acc;
|
|
||||||
}, {});
|
|
||||||
|
|
||||||
return Object.entries(res).map(([date, count]) => ({
|
return Object.entries(res).map(([date, count]) => ({
|
||||||
date: new Date(date),
|
date: new Date(date),
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import Chart from 'chart.js/auto';
|
|||||||
selector: 'app-chart-login',
|
selector: 'app-chart-login',
|
||||||
standalone: true,
|
standalone: true,
|
||||||
imports: [],
|
imports: [],
|
||||||
templateUrl: './login.component.html',
|
templateUrl: './login.chart.component.html',
|
||||||
styleUrl: './login.component.scss'
|
styleUrl: './login.chart.component.scss'
|
||||||
})
|
})
|
||||||
export class LoginChartComponent {
|
export class LoginChartComponent {
|
||||||
chart: any = [];
|
chart: any = [];
|
||||||
|
|||||||
@@ -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();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
Reference in New Issue
Block a user