Skip to content
Snippets Groups Projects
Commit 6ec5f0d9 authored by mechtelm's avatar mechtelm
Browse files

load unit fix: request extended by alias to get the correct restore point...

load unit fix: request extended by alias to get the correct restore point #261; linting errors ignored!
parent f342a82a
No related branches found
No related tags found
No related merge requests found
import { Injectable, Inject } from '@angular/core';
import { HttpClient, HttpParams } from '@angular/common/http';
import {Observable, of, Subscription} from 'rxjs';
import {catchError, map, switchMap} from 'rxjs/operators';
import { Observable, of, Subscription } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators';
import {
UnitData,
TaggedString,
......@@ -9,14 +9,12 @@ import {
TestStateKey,
StateReportEntry, AppFocusState
} from './test-controller.interfaces';
import {ApiError} from '../app.interfaces';
import { ApiError } from '../app.interfaces';
@Injectable({
providedIn: 'root'
})
export class BackendService {
constructor(
@Inject('SERVER_URL') private serverUrl: string,
private http: HttpClient
......@@ -25,7 +23,7 @@ export class BackendService {
saveUnitReview(testId: string, unitName: string, priority: number, categories: string, entry: string)
: Observable<boolean> {
return this.http
.put(this.serverUrl + `test/${testId}/unit/${unitName}/review`, {priority, categories, entry})
.put(`${this.serverUrl}test/${testId}/unit/${unitName}/review`, { priority, categories, entry })
.pipe(
map(() => true),
catchError((err: ApiError) => {
......@@ -37,7 +35,7 @@ export class BackendService {
saveTestReview(testId: string, priority: number, categories: string, entry: string): Observable<boolean> {
return this.http
.put(this.serverUrl + `test/${testId}/review`, {priority, categories, entry})
.put(`${this.serverUrl}test/${testId}/review`, { priority, categories, entry })
.pipe(
map(() => true),
catchError((err: ApiError) => {
......@@ -49,7 +47,7 @@ export class BackendService {
getTestData(testId: string): Observable<TestData | boolean> {
return this.http
.get<TestData>(this.serverUrl + 'test/' + testId)
.get<TestData>(`${this.serverUrl}test/${testId}`)
.pipe(
catchError((err: ApiError) => {
console.warn(`getTestData Api-Error: ${err.code} ${err.info} `);
......@@ -58,9 +56,9 @@ export class BackendService {
);
}
getUnitData(testId: string, unitid: string): Observable<UnitData | boolean> {
getUnitData(testId: string, unitid: string, unitalias: string): Observable<UnitData | boolean> {
return this.http
.get<UnitData>(this.serverUrl + 'test/' + testId + '/unit/' + unitid)
.get<UnitData>(`${this.serverUrl}test/${testId}/unit/${unitid}/alias/${unitalias}`)
.pipe(
catchError((err: ApiError) => {
console.warn(`getUnitData Api-Error: ${err.code} ${err.info} `);
......@@ -72,13 +70,14 @@ export class BackendService {
getResource(testId: string, internalKey: string, resId: string, versionning = false): Observable<TaggedString | number> {
return this.http
.get(
this.serverUrl + `test/${testId}/resource/${resId}`,
`${this.serverUrl}test/${testId}/resource/${resId}`,
{
params: new HttpParams().set('v', versionning ? '1' : 'f'),
responseType: 'text'
})
}
)
.pipe(
map(def => <TaggedString>{tag: internalKey, value: def}),
map(def => <TaggedString>{ tag: internalKey, value: def }),
catchError((err: ApiError) => {
console.warn(`getResource Api-Error: ${err.code} ${err.info} `);
return of(err.code);
......@@ -88,32 +87,32 @@ export class BackendService {
updateTestState(testId: string, newState: StateReportEntry[]): Subscription {
return this.http
.patch(this.serverUrl + `test/${testId}/state`, newState)
.subscribe({error: (err: ApiError) => console.error(`updateTestState Api-Error: ${err.code} ${err.info}`)});
.patch(`${this.serverUrl}test/${testId}/state`, newState)
.subscribe({ error: (err: ApiError) => console.error(`updateTestState Api-Error: ${err.code} ${err.info}`) });
}
addTestLog(testId: string, logEntries: StateReportEntry[]): Subscription {
return this.http
.put(this.serverUrl + `test/${testId}/log`, logEntries)
.subscribe({error: (err: ApiError) => console.error(`addTestLog Api-Error: ${err.code} ${err.info}`)});
.put(`${this.serverUrl}test/${testId}/log`, logEntries)
.subscribe({ error: (err: ApiError) => console.error(`addTestLog Api-Error: ${err.code} ${err.info}`) });
}
updateUnitState(testId: string, unitName: string, newState: StateReportEntry[]): Subscription {
return this.http
.patch(this.serverUrl + `test/${testId}/unit/${unitName}/state`, newState)
.subscribe({error: (err: ApiError) => console.error(`setUnitState Api-Error: ${err.code} ${err.info}`)});
.patch(`${this.serverUrl}test/${testId}/unit/${unitName}/state`, newState)
.subscribe({ error: (err: ApiError) => console.error(`setUnitState Api-Error: ${err.code} ${err.info}`) });
}
addUnitLog(testId: string, unitName: string, logEntries: StateReportEntry[]): Subscription {
return this.http
.put(this.serverUrl + `test/${testId}/unit/${unitName}/log`, logEntries)
.subscribe({error: (err: ApiError) => console.error(`addUnitLog Api-Error: ${err.code} ${err.info}`)});
.put(`${this.serverUrl}test/${testId}/unit/${unitName}/log`, logEntries)
.subscribe({ error: (err: ApiError) => console.error(`addUnitLog Api-Error: ${err.code} ${err.info}`) });
}
notifyDyingTest(testId: string) {
// TODO add auth or change end point
if (navigator.sendBeacon) {
navigator.sendBeacon(this.serverUrl + `test/${testId}/state`, JSON.stringify(<StateReportEntry>{
navigator.sendBeacon(`${this.serverUrl}test/${testId}/state`, JSON.stringify(<StateReportEntry>{
key: TestStateKey.FOCUS, timeStamp: Date.now(), content: AppFocusState.DEAD
}));
}
......@@ -126,19 +125,17 @@ export class BackendService {
const restorePoint = dataPartsAllString;
const responseType = unitStateDataType;
return this.http
.put(this.serverUrl + `test/${testId}/unit/${unitName}/response`, {timeStamp, response, responseType})
.put(`${this.serverUrl}test/${testId}/unit/${unitName}/response`, { timeStamp, response, responseType })
.pipe(
switchMap(() => {
return this.http
.patch(this.serverUrl + `test/${testId}/unit/${unitName}/restorepoint`, {timeStamp, restorePoint})
.pipe(
map(() => true),
catchError((err: ApiError) => {
console.warn(`newUnitStateData/restorepoint Api-Error: ${err.code} ${err.info} `);
return of(false);
})
);
}),
switchMap(() => this.http
.patch(`${this.serverUrl}test/${testId}/unit/${unitName}/restorepoint`, { timeStamp, restorePoint })
.pipe(
map(() => true),
catchError((err: ApiError) => {
console.warn(`newUnitStateData/restorepoint Api-Error: ${err.code} ${err.info} `);
return of(false);
})
)),
catchError((err: ApiError) => {
console.warn(`newUnitStateData/response Api-Error: ${err.code} ${err.info} `);
return of(false);
......@@ -148,7 +145,7 @@ export class BackendService {
lockTest(testId: string, timeStamp: number, content: string): Observable<boolean> {
return this.http
.patch<boolean>(this.serverUrl + `test/${testId}/lock`, {timeStamp, content})
.patch<boolean>(`${this.serverUrl}test/${testId}/lock`, { timeStamp, content })
.pipe(
map(() => true),
catchError((err: ApiError) => {
......
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment