Show more data in webapp deliveries-table
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import { Injectable, inject } from '@angular/core';
|
||||
import { Observable, of, catchError, map, shareReplay } from 'rxjs';
|
||||
import { ApiService } from './api.service';
|
||||
|
||||
export interface ResolvedClient {
|
||||
clientId: string;
|
||||
clientName: string | null;
|
||||
userId: string;
|
||||
userName: string | null;
|
||||
agentModel: string;
|
||||
agentVersion: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class ClientCacheService {
|
||||
private apiService = inject(ApiService);
|
||||
|
||||
private cache = new Map<string, Observable<ResolvedClient | null>>();
|
||||
|
||||
resolveClient(clientId: string): Observable<ResolvedClient | null> {
|
||||
if (!this.cache.has(clientId)) {
|
||||
const request$ = this.apiService.getClientPreview(clientId).pipe(
|
||||
map(response => ({
|
||||
clientId: response.client.client_id,
|
||||
clientName: response.client.name,
|
||||
userId: response.user.user_id,
|
||||
userName: response.user.username,
|
||||
agentModel: response.client.agent_model,
|
||||
agentVersion: response.client.agent_version,
|
||||
})),
|
||||
catchError(() => of(null)),
|
||||
shareReplay(1)
|
||||
);
|
||||
this.cache.set(clientId, request$);
|
||||
}
|
||||
return this.cache.get(clientId)!;
|
||||
}
|
||||
|
||||
clearCache(): void {
|
||||
this.cache.clear();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user