Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 | 3x 3x 3x 5x 5x 5x 5x 5x 5x 5x 5x 2x 14x 2x 2x 1x 1x 1x | import { HttpClient, HttpHeaders } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { JsonSimpleValue, LogMessageDetail } from '@reflex/shared-types';
import { Observable } from 'rxjs/internal/Observable';
import { catchError, concatMap, tap } from 'rxjs/operators';
import { BASE_URL } from 'src/shared/tokens/base-url.token';
@Injectable({
providedIn: 'root'
})
export class LogService {
// eslint-disable-next-line @typescript-eslint/naming-convention
protected readonly headers = new HttpHeaders({ 'Content-Type': 'application/json' });
private readonly http = inject(HttpClient);
private readonly baseUrl = inject(BASE_URL);
private readonly baseRoute = 'api/Log';
private readonly route = `${this.baseUrl}${this.baseRoute}/Messages/`;
private readonly routeAdd = `${this.baseUrl}${this.baseRoute}/Add/`;
private index = 0;
public getLogs(): Observable<LogMessageDetail> {
const list = this.http
.get<Array<LogMessageDetail>>(`${this.route}${this.index}`)
.pipe(
tap((completeMessages) => {
this.index = Math.max(...completeMessages.map((elem) => elem.id));
}),
concatMap((result) => [...result]),
catchError((error) => {
console.error(error);
throw error;
})
);
return list;
}
public sendErrorLog(msg: string): void {
const value: JsonSimpleValue = {
name: 'message',
value: msg
};
this.http
.post<JsonSimpleValue>(this.routeAdd, value, { headers: this.headers })
.subscribe(console.log, console.error);
}
public reset(): void {
this.index = 0;
}
}
|