Newer
Older
import { Injectable, Inject } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import { Observable, of } from 'rxjs';

Martin Mechtel
committed
import { catchError, map } from 'rxjs/operators';
import {UnitData, TaggedString, TestData} from './test-controller.interfaces';
@Injectable({
providedIn: 'root'
})
export class BackendService {
constructor(
@Inject('SERVER_URL') private serverUrl: string,
private http: HttpClient
saveUnitReview(testId: string, unitName: string, priority: number, categories: string, entry: string)
: Observable<boolean> {
.put(this.serverUrl + `test/${testId}/unit/${unitName}/review`, {priority, categories, entry})
.pipe(
map(() => true),
catchError(() => of(false))
);
saveBookletReview(testId: string, priority: number, categories: string, entry: string): Observable<boolean> {
.put(this.serverUrl + `test/${testId}/review`, {priority, categories, entry})
.pipe(
map(() => true),
catchError(() => of(false))
);
getTestData(testId: string): Observable<TestData | number> {
.get<TestData>(this.serverUrl + 'test/' + testId)
.pipe(
catchError(errCode => of(errCode))
);
getUnitData(testId: string, unitid: string): Observable<UnitData | number> {
.get<UnitData>(this.serverUrl + 'test/' + testId + '/unit/' + unitid)
getResource(testId: string, internalKey: string, resId: string, versionning = false): Observable<TaggedString | number> {
this.serverUrl + `test/${testId}/resource/${resId}`,
{
params: new HttpParams().set('v', versionning ? '1' : 'f'),
responseType: 'text'
})
map(def => <TaggedString>{tag: internalKey, value: def}),
addUnitLog(testId: string, timestamp: number, unitName: string, entry: string): Observable<boolean> {
.put(this.serverUrl + `test/${testId}/unit/${unitName}/log`, {timestamp, entry})
.pipe(
map(() => true),
catchError(() => of(false))
);
addBookletLog(testId: string, timestamp: number, entry: string): Observable<boolean> {
.put(this.serverUrl + `test/${testId}/log`, {timestamp, entry})
.pipe(
map(() => true),
catchError(() => of(false))
);
setUnitState(testId: string, unitName: string, stateKey: string, state: string): Observable<boolean> {
.patch(this.serverUrl + `test/${testId}/unit/${unitName}/state`, {key: stateKey, value: state})
.pipe(
map(() => true),
catchError(() => of(false))
);
setBookletState(testId: string, stateKey: string, state: string): Observable<boolean> {
.patch(this.serverUrl + `test/${testId}/state`, {key: stateKey, value: state})
.pipe(
map(() => true),
catchError(() => of(false))
);
newUnitResponse(testId: string, timestamp: number, unitName: string, response: string, responseType: string)
: Observable<boolean> {
.put(this.serverUrl + `test/${testId}/unit/${unitName}/response`, {timestamp, response, responseType})
.pipe(
map(() => true),
catchError(() => of(false))
);
newUnitRestorePoint(testId: string, unitName: string, timestamp: number, restorePoint: string): Observable<boolean> {
.patch(this.serverUrl + `test/${testId}/unit/${unitName}/restorepoint`, {timestamp, restorePoint})
.pipe(
map(() => true),
catchError(() => of(false))
);