argos/dmp-frontend/src/app/core/services/supportive-material/supportive-material.service.ts

83 lines
2.9 KiB
TypeScript

import { Injectable } from "@angular/core";
import { ConfigurationService } from "../configuration/configuration.service";
import { HttpClient, HttpResponse } from "@angular/common/http";
import { Observable, throwError } from "rxjs";
import { SupportiveMaterial, SupportiveMaterialPersist } from "@app/core/model/supportive-material/supportive-material";
import { BaseHttpV2Service } from "../http/base-http-v2.service";
import { SupportiveMaterialLookup } from "@app/core/query/supportive-material.lookup";
import { QueryResult } from "@common/model/query-result";
import { catchError } from "rxjs/operators";
import { Guid } from "@common/types/guid";
import { nameof } from "ts-simple-nameof";
import { IsActive } from "@app/core/common/enum/is-active.enum";
import { SupportiveMaterialFieldType } from "@app/core/common/enum/supportive-material-field-type";
@Injectable()
export class SupportiveMaterialService{
constructor(
private http: BaseHttpV2Service,
private configurationService: ConfigurationService
) {
}
private get apiBase(): string { return `${this.configurationService.server}supportive-material`; }
queryPublic(q: SupportiveMaterialLookup): Observable<HttpResponse<Blob>> {
return this.http.post<HttpResponse<Blob>>(`${this.apiBase}/public`, q , {responseType: 'blob', observe: 'response' });
}
query(q: SupportiveMaterialLookup): Observable<QueryResult<SupportiveMaterial>> {
const url = `${this.apiBase}/query`;
return this.http.post<QueryResult<SupportiveMaterial>>(url, q).pipe(catchError((error: any) => throwError(error)));
}
getSingle(id: Guid, reqFields: string[] = []): Observable<SupportiveMaterial> {
const url = `${this.apiBase}/${id}`;
const options = { params: { f: reqFields } };
return this.http
.get<SupportiveMaterial>(url, options).pipe(
catchError((error: any) => throwError(error)));
}
persist(item: SupportiveMaterialPersist): Observable<SupportiveMaterial> {
const url = `${this.apiBase}/persist`;
return this.http
.post<SupportiveMaterial>(url, item).pipe(
catchError((error: any) => throwError(error)));
}
delete(id: Guid): Observable<SupportiveMaterial> {
const url = `${this.apiBase}/${id}`;
return this.http
.delete<SupportiveMaterial>(url).pipe(
catchError((error: any) => throwError(error)));
}
// LOOKUP
public static DefaultSupportiveMaterialLookup(): SupportiveMaterialLookup{
const lookup = new SupportiveMaterialLookup();
lookup.project = {
fields: [
nameof<SupportiveMaterial>(x => x.id),
nameof<SupportiveMaterial>(x => x.type),
nameof<SupportiveMaterial>(x => x.languageCode),
nameof<SupportiveMaterial>(x => x.payload),
nameof<SupportiveMaterial>(x => x.createdAt),
nameof<SupportiveMaterial>(x => x.updatedAt),
nameof<SupportiveMaterial>(x => x.isActive)
]
};
lookup.order = { items: [nameof<SupportiveMaterial>(x => x.type)] };
lookup.page = { offset: 0, size: 10 };
lookup.isActive = [IsActive.Active];
return lookup;
}
}