All files / tools/ReFlex.TrackingServer/ClientApp/src/shared/services version.service.ts

31.25% Statements 5/16
60% Branches 3/5
0% Functions 0/7
30.76% Lines 4/13

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 403x       3x 3x                     3x                                              
import { HttpClient } from '@angular/common/http';
import { Injectable, inject } from '@angular/core';
import { AppVersionInfo } from '@reflex/shared-types';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { BASE_URL } from 'src/shared/tokens/base-url.token';
 
interface ClientPackageInfo {
  name: string;
  version: string;
  dependencies: Record<string, string>;
}
 
@Injectable({
  providedIn: 'root'
})
export class VersionInfoService {
  private readonly http = inject(HttpClient);
  private readonly baseUrl = inject(BASE_URL);
 
  private readonly packageFile = 'assets/data/package.json';
  private readonly versionAddress = `${this.baseUrl}api/versionInfo`;
 
  public getServerVersionInfo(): Observable<Array<AppVersionInfo>> {
    return this.http.get<Array<AppVersionInfo>>(this.versionAddress);
  }
 
  public getClientVersionInfo(): Observable<Array<AppVersionInfo>> {
    return this.http.get<ClientPackageInfo>(this.packageFile).pipe(
      map((result) => Object.entries(result.dependencies).map(([name, version]) => ({ name, version })))
    );
  }
 
  public getAppVersionInfo(): Observable<AppVersionInfo> {
    return this.http.get<ClientPackageInfo>(this.packageFile).pipe(
      map(({ name, version }) => ({ name, version }))
    );
  }
}