All files / src/app backend.service.ts

7.69% Statements 1/13
0% Branches 0/2
0% Functions 0/9
7.69% Lines 1/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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57                    1x                                                                                            
import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { catchError } from 'rxjs/operators';
import { SysCheckInfo, AuthData, AppError } from './app.interfaces';
import { SysConfig } from './shared/shared.module';
 
@Injectable({
  providedIn: 'root'
})
export class BackendService {
  constructor(
    @Inject('BACKEND_URL') private readonly serverUrl: string,
    private http: HttpClient
  ) {}
 
  login(loginType: 'admin' | 'login', name: string, password: string | undefined = undefined): Observable<AuthData> {
    return this.http.put<AuthData>(`${this.serverUrl}session/${loginType}`, { name, password });
  }
 
  codeLogin(code: string): Observable<AuthData> {
    return this.http.put<AuthData>(`${this.serverUrl}session/person`, { code });
  }
 
  getSessionData(): Observable<AuthData> {
    return this.http.get<AuthData>(`${this.serverUrl}session`);
  }
 
  startTest(bookletName: string): Observable<number> {
    return this.http
      .put<number>(`${this.serverUrl}test`, { bookletName });
  }
 
  getSysConfig(): Observable<SysConfig> {
    return this.http
      .get<SysConfig>(`${this.serverUrl}system/config`)
      .pipe(
        catchError((error: AppError) => {
          Iif (error.code !== 503) {
            error.type = 'fatal';
          }
          throw error;
        })
      );
  }
 
  checkIfSysCheckModeExists(): Observable<boolean> {
    return this.http
      .get<boolean>(`${this.serverUrl}sys-check-mode`);
  }
 
  getSysCheckInfosAcrossWorkspaces(): Observable<SysCheckInfo[]> {
    return this.http
      .get<SysCheckInfo[]>(`${this.serverUrl}sys-checks`);
  }
}