brewman/overlord/src/app/raw-material-cost/raw-material-cost.service.ts
tanshu 5ea09df272 Prettied, Linted and updated angular.json according to the latest schematic of Angular CLI.
Now all that is needed is to make it ready for strict compiling.
Removed eslint-plugin-prettier as it is not recommended and causes errors for both eslint and prettier

Bumped to v8.0.0
2020-10-10 08:45:05 +05:30

42 lines
1.2 KiB
TypeScript

import { HttpClient, HttpParams } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/internal/Observable';
import { catchError } from 'rxjs/operators';
import { ErrorLoggerService } from '../core/error-logger.service';
import { RawMaterialCost } from './raw-material-cost';
const url = '/api/raw-material-cost';
const serviceName = 'RawMaterialCostService';
@Injectable({
providedIn: 'root',
})
export class RawMaterialCostService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
list(id: string, startDate: string, finishDate): Observable<RawMaterialCost> {
const options = { params: new HttpParams() };
if (startDate !== null) {
options.params = options.params.set('s', startDate);
}
if (finishDate !== null) {
options.params = options.params.set('f', finishDate);
}
let listUrl = '';
if (id !== null) {
listUrl = `${url}/${id}`;
} else if (startDate || finishDate) {
listUrl = `${url}/data`;
} else {
listUrl = url;
}
return <Observable<RawMaterialCost>>(
this.http
.get<RawMaterialCost>(listUrl, options)
.pipe(catchError(this.log.handleError(serviceName, 'list')))
);
}
}