src/app/services/persistence.service.ts
Properties |
|
Methods |
constructor(collection: string, http: HttpClient)
|
|||||||||
Defined in src/app/services/persistence.service.ts:9
|
|||||||||
Parameters :
|
Protected collection |
Type : string
|
Default value : ''
|
Defined in src/app/services/persistence.service.ts:8
|
Protected http |
Type : HttpClient
|
Defined in src/app/services/persistence.service.ts:9
|
count |
count()
|
Defined in src/app/services/persistence.service.ts:53
|
Returns :
Observable<any>
|
createAuthorizationHeader |
createAuthorizationHeader()
|
Defined in src/app/services/persistence.service.ts:20
|
Returns :
HttpHeaders
|
delete | ||||
delete(id)
|
||||
Defined in src/app/services/persistence.service.ts:38
|
||||
Parameters :
Returns :
Observable<any>
|
errorHandler | ||||
errorHandler(error)
|
||||
Defined in src/app/services/persistence.service.ts:16
|
||||
Parameters :
Returns :
any
|
findByExperiment | ||||
findByExperiment(experimentId)
|
||||
Defined in src/app/services/persistence.service.ts:59
|
||||
Parameters :
Returns :
Observable<any>
|
get | ||||
get(id)
|
||||
Defined in src/app/services/persistence.service.ts:43
|
||||
Parameters :
Returns :
Observable<any>
|
getAll |
getAll()
|
Defined in src/app/services/persistence.service.ts:48
|
Returns :
Observable<any>
|
post | ||||
post(obj)
|
||||
Defined in src/app/services/persistence.service.ts:28
|
||||
Parameters :
Returns :
Observable<any>
|
put | ||||
put(obj)
|
||||
Defined in src/app/services/persistence.service.ts:33
|
||||
Parameters :
Returns :
Observable<any>
|
import {HttpClient, HttpHeaders} from "@angular/common/http";
import {Observable} from "rxjs";
import {catchError} from "rxjs/operators";
import {UserService} from "./user.service";
export class PersistenceService {
protected collection = '';
protected http: HttpClient;
constructor(collection: string, http: HttpClient) {
this.collection = collection;
this.http = http;
}
errorHandler(error) {
return Promise.reject(error && error.json ? error.json() : error);
}
createAuthorizationHeader(): HttpHeaders {
console.log("Auth ---", UserService.user);
return new HttpHeaders({
'Content-Type': 'application/json',
'authorization': UserService.user.token
});
}
post(obj): Observable<any> {
return this.http.post(`${UserService.baseUrl}/${this.collection}/async`, obj, {headers: this.createAuthorizationHeader()})
.pipe(catchError(this.errorHandler));
}
put(obj): Observable<any> {
return this.http.post(`${UserService.baseUrl}/${this.collection}/async`, obj, {headers: this.createAuthorizationHeader()})
.pipe(catchError(this.errorHandler));
}
delete(id): Observable<any> {
return this.http.delete(`${UserService.baseUrl}/${this.collection}/${id}`, {headers: this.createAuthorizationHeader()})
.pipe(catchError(this.errorHandler));
}
get(id): Observable<any> {
return this.http.get(`${UserService.baseUrl}/${this.collection}/${id}`, {headers: this.createAuthorizationHeader()})
.pipe(catchError(this.errorHandler));
}
getAll(): Observable<any> {
return this.http.get(`${UserService.baseUrl}/${this.collection}`, {headers: this.createAuthorizationHeader()})
.pipe(catchError(this.errorHandler));
}
count(): Observable<any> {
return this.http.get(`${UserService.baseUrl}/${this.collection}/count`, {headers: this.createAuthorizationHeader()})
.pipe(catchError(this.errorHandler));
}
findByExperiment(experimentId): Observable<any> {
return this.http.get(`${UserService.baseUrl}/${this.collection}/by-experiment/${experimentId}`, {headers: this.createAuthorizationHeader()})
.pipe(catchError(this.errorHandler));
}
}