Settle Options are now stored in the Database and can be updated

This commit is contained in:
2020-12-13 09:44:32 +05:30
parent d65379a068
commit 27aa4d12a6
72 changed files with 1326 additions and 551 deletions

View File

@ -0,0 +1,69 @@
import { HttpClient, HttpHeaders } 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 { SettleOption } from '../core/settle-option';
import { VoucherType } from '../sales/bills/voucher-type';
const httpOptions = {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
};
const url = '/api/settle-options';
const serviceName = 'SettleOptionService';
@Injectable({
providedIn: 'root',
})
export class SettleOptionService {
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
get(id: string | null): Observable<SettleOption> {
const getUrl: string = id === null ? url : `${url}/${id}`;
return this.http
.get<SettleOption>(getUrl)
.pipe(
catchError(this.log.handleError(serviceName, `get id=${id}`)),
) as Observable<SettleOption>;
}
list(): Observable<SettleOption[]> {
return this.http
.get<SettleOption[]>(`${url}/list`)
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<SettleOption[]>;
}
listForType(voucherType: VoucherType): Observable<SettleOption[]> {
return this.http
.get<SettleOption[]>(`${url}/for-type/${voucherType}`)
.pipe(
catchError(this.log.handleError(serviceName, `listForType voucherType=${voucherType}`)),
) as Observable<SettleOption[]>;
}
save(settleOption: SettleOption): Observable<SettleOption> {
return this.http
.post<SettleOption>(url, settleOption, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'save'))) as Observable<SettleOption>;
}
update(settleOption: SettleOption): Observable<SettleOption> {
return this.http
.put<SettleOption>(`${url}/${settleOption.id}`, settleOption, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'update'))) as Observable<SettleOption>;
}
saveOrUpdate(settleOption: SettleOption): Observable<SettleOption> {
if (!settleOption.id) {
return this.save(settleOption);
}
return this.update(settleOption);
}
delete(id: number): Observable<SettleOption> {
return this.http
.delete<SettleOption>(`${url}/${id}`, httpOptions)
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<SettleOption>;
}
}