import { HttpHeaders } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Lock, LockPersist, LockStatus } from '@app/core/model/lock/lock.model'; import { LockLookup } from '@app/core/query/lock.lookup'; import { QueryResult } from '@common/model/query-result'; import { FilterService } from '@common/modules/text-filter/filter-service'; import { Guid } from '@common/types/guid'; import { Observable, throwError } from 'rxjs'; import { catchError } from 'rxjs/operators'; import { ConfigurationService } from '../configuration/configuration.service'; import { BaseHttpV2Service } from '../http/base-http-v2.service'; import { LockTargetType } from '@app/core/common/enum/lock-target-type'; @Injectable() export class LockService { private headers = new HttpHeaders(); constructor(private http: BaseHttpV2Service, private configurationService: ConfigurationService, private filterService: FilterService) { } private get apiBase(): string { return `${this.configurationService.server}lock`; } query(q: LockLookup): Observable> { const url = `${this.apiBase}/query`; return this.http.post>(url, q).pipe(catchError((error: any) => throwError(error))); } getSingle(id: Guid, reqFields: string[] = []): Observable { const url = `${this.apiBase}/${id}`; const options = { params: { f: reqFields } }; return this.http .get(url, options).pipe( catchError((error: any) => throwError(error))); } persist(item: LockPersist): Observable { const url = `${this.apiBase}/persist`; return this.http .post(url, item).pipe( catchError((error: any) => throwError(error))); } delete(id: Guid): Observable { const url = `${this.apiBase}/${id}`; return this.http .delete(url).pipe( catchError((error: any) => throwError(error))); } checkLockStatus(targetId: Guid, reqFields: string[] = []): Observable { const url = `${this.apiBase}/target/status/${targetId}`; const options = { params: { f: reqFields } }; return this.http.get(url, options) .pipe(catchError((error: any) => throwError(error))); } lock(targetId: Guid, targetType: LockTargetType): Observable { return this.http.get(`${this.apiBase}/target/lock/${targetId}/${targetType}`) .pipe(catchError((error: any) => throwError(error))); } touchLock(targetId: Guid): Observable { return this.http.get(`${this.apiBase}/target/touch/${targetId}`) .pipe(catchError((error: any) => throwError(error))); } unlockTarget(targetId: Guid): Observable { return this.http.delete(`${this.apiBase}/target/unlock/${targetId}`) .pipe(catchError((error: any) => throwError(error))); } getSingleWithTarget(targetId: Guid, reqFields: string[] = []): Observable { const url = `${this.apiBase}/target/${targetId}`; const options = { params: { f: reqFields } }; return this.http .get(url, options).pipe( catchError((error: any) => throwError(error))); } }