Newer
Older
import { Injectable, Inject } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable, of } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators';
SysCheckInfo,
AuthData,
WorkspaceData,
BookletData, ApiError, AccessObject
@Injectable({
providedIn: 'root'
})
export class BackendService {
constructor(

Martin Mechtel
committed
@Inject('SERVER_URL') private readonly serverUrl: string,
login(name: string, password: string): Observable<AuthData | number> {
.put<AuthData>(`${this.serverUrl}session/admin`, { name, password })
catchError((err: ApiError) => {
console.warn(`login Api-Error: ${err.code} ${err.info} `);
}),
if (typeof authData === 'number') {
const errCode = authData as number;
if (errCode === 400) {

Martin Mechtel
committed
return this.http
.put<AuthData>(`${this.serverUrl}session/login`, { name, password })
.pipe(catchError((err: ApiError) => of(err.code)));

Martin Mechtel
committed
}

Martin Mechtel
committed
}

Martin Mechtel
committed
})
}
nameOnlyLogin(name: string): Observable<AuthData | number> {
return this.http
catchError((err: ApiError) => {
console.warn(`nameOnlyLogin Api-Error: ${err.code} ${err.info} `);
})
codeLogin(code: string): Observable<AuthData | number> {
return this.http
catchError((err: ApiError) => {
console.warn(`codeLogin Api-Error: ${err.code} ${err.info} `);
})
getWorkspaceData(workspaceId: string): Observable<WorkspaceData> {
return this.http
.get<WorkspaceData>(`${this.serverUrl}workspace/${workspaceId}`)
.pipe(catchError(() => {
console.warn(`get workspace data failed for ${workspaceId}`);
return of(<WorkspaceData>{
id: workspaceId,
name: workspaceId,
}));
// TODO find consistent terminology. in XSD they are called name & label
// and likewise (mostly) in newer BE-versions
.get<NameAndLabel>(`${this.serverUrl}monitor/group/${groupName}`)
.pipe(map((r: NameAndLabel): AccessObject => ({ id: r.name, name: r.label })))
.pipe(catchError(() => {
console.warn(`get group data failed for ${groupName}`);
return of(<AccessObject>{
id: groupName,
name: groupName
});
}));
}
getSessionData(): Observable<AuthData | number> {
return this.http
catchError((err: ApiError) => of(err.code))
getBookletData(bookletId: string): Observable<BookletData> {
return this.http
.get<BookletData>(this.serverUrl + 'booklet/' + bookletId + '/data')
.pipe(
map(bData => {
bData.id = bookletId;
console.warn('get booklet data failed for ' + bookletId);
return of(<BookletData>{
startTest(bookletName: string): Observable<string | number> {
catchError((err: ApiError) => of(err.code))

mechtelm
committed
getSysConfig(): Observable<SysConfig> {
return this.http

mechtelm
committed
return this.http

mechtelm
committed
.pipe(
catchError(() => {

mechtelm
committed
})
);
}