FarmMapsLib/projects/common/src/fm/services/codelistitem.service.ts
Peter Bastiani e8845a092a
All checks were successful
FarmMaps.Develop/FarmMapsLib/develop This commit looks good
AW-803 Add CodeListItem + service.
2020-01-21 14:52:36 +01:00

27 lines
1.0 KiB
TypeScript

import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { HttpClient, HttpParams } from "@angular/common/http";
import { AppConfig } from "../shared/app.config";
import { ICodeListItem } from '../models/code.list.item';
@Injectable({
providedIn: 'root',
})
export class CodeListItemService {
constructor(public httpClient: HttpClient, public appConfig: AppConfig) {
}
ApiEndpoint() {
return this.appConfig.getConfig("apiEndPoint");
}
getCodeListItems(codelist: string[], codegroup?: string, dataFilter?: any, onlyBetweenValidFromAndTo: boolean = true): Observable<ICodeListItem[]> {
var params = new HttpParams();
params = params.append("cl", codelist.join(","));
if (codegroup) params = params.append("g", codegroup);
if (onlyBetweenValidFromAndTo) params = params.append("v", onlyBetweenValidFromAndTo);
if (dataFilter) params = params.append("df", dataFilter);
return this.httpClient.get<ICodeListItem>(`${this.ApiEndpoint()}/api/v1/codelistitems/`, { params: params });
}
}