Fix: DiscountLimit was not scaled to 100 in MenuCategory detail. So it is now chaled in the json and scaled back in the frontend for the list as that was not supposed to be scaled. Feature: Modifier is now done Fix: In product save, it was checking menu_category second time again instead of sale_category
89 lines
2.8 KiB
TypeScript
89 lines
2.8 KiB
TypeScript
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs/internal/Observable';
|
|
import { catchError } from 'rxjs/operators';
|
|
import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http';
|
|
import { Modifier } from '../core/modifier';
|
|
import { ErrorLoggerService } from '../core/error-logger.service';
|
|
|
|
const httpOptions = {
|
|
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
|
};
|
|
|
|
const url = '/v1/modifiers';
|
|
const serviceName = 'ModifierService';
|
|
|
|
@Injectable({providedIn: 'root'})
|
|
export class ModifierService {
|
|
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
|
}
|
|
|
|
get(id: string): Observable<Modifier> {
|
|
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
|
return <Observable<Modifier>>this.http.get<Modifier>(getUrl)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
|
);
|
|
}
|
|
|
|
list(): Observable<Modifier[]> {
|
|
const options = {params: new HttpParams().set('l', '')};
|
|
return <Observable<Modifier[]>>this.http.get<Modifier[]>(url, options)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'getList'))
|
|
);
|
|
}
|
|
|
|
save(modifier: Modifier): Observable<Modifier> {
|
|
return <Observable<Modifier>>this.http.post<Modifier>(`${url}/new`, modifier, httpOptions)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'save'))
|
|
);
|
|
}
|
|
|
|
update(modifier: Modifier): Observable<Modifier> {
|
|
return <Observable<Modifier>>this.http.put<Modifier>(`${url}/${modifier.id}`, modifier, httpOptions)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'update'))
|
|
);
|
|
}
|
|
|
|
updateSortOrder(list: Modifier[]): Observable<boolean> {
|
|
return <Observable<boolean>>this.http.post<Modifier[]>(url, list, httpOptions)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'updateSortOrder'))
|
|
);
|
|
}
|
|
|
|
saveOrUpdate(modifier: Modifier): Observable<Modifier> {
|
|
if (!modifier.id) {
|
|
return this.save(modifier);
|
|
} else {
|
|
return this.update(modifier);
|
|
}
|
|
}
|
|
|
|
delete(id: string): Observable<Modifier> {
|
|
return <Observable<Modifier>>this.http.delete<Modifier>(`${url}/${id}`, httpOptions)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'delete'))
|
|
);
|
|
}
|
|
|
|
autocomplete(term: string): Observable<Modifier[]> {
|
|
const options = {params: new HttpParams().set('t', term)};
|
|
return <Observable<Modifier[]>>this.http.get<Modifier[]>(url, options)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'autocomplete'))
|
|
);
|
|
}
|
|
|
|
balance(id: string, date: string): Observable<number> {
|
|
const options = {params: new HttpParams().set('b', 'true').set('d', date)};
|
|
return <Observable<number>>this.http.get<number>(`${url}/${id}`, options)
|
|
.pipe(
|
|
catchError(this.log.handleError(serviceName, 'balance'))
|
|
);
|
|
}
|
|
}
|