Product Group renamed to Menu Category
Extracted Product Group -> Group_type to a a new object called Sale Category. Moved tax from product to Sale Category for uniform taxes on types of sales.
This commit is contained in:
72
bookie/src/app/sale-category/sale-category.service.ts
Normal file
72
bookie/src/app/sale-category/sale-category.service.ts
Normal file
@ -0,0 +1,72 @@
|
||||
import {Injectable} from '@angular/core';
|
||||
import {HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';
|
||||
import {ErrorLoggerService} from '../core/error-logger.service';
|
||||
import {catchError} from 'rxjs/operators';
|
||||
import {Observable} from 'rxjs/internal/Observable';
|
||||
import {SaleCategory} from '../core/sale-category';
|
||||
|
||||
const httpOptions = {
|
||||
headers: new HttpHeaders({'Content-Type': 'application/json'})
|
||||
};
|
||||
const url = '/v1/sale-categories';
|
||||
const serviceName = 'SaleCategoryService';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class SaleCategoryService {
|
||||
constructor(private http: HttpClient, private log: ErrorLoggerService) {
|
||||
}
|
||||
|
||||
get(id: string): Observable<SaleCategory> {
|
||||
const getUrl: string = (id === null) ? `${url}/new` : `${url}/${id}`;
|
||||
return <Observable<SaleCategory>>this.http.get<SaleCategory>(getUrl)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, `get id=${id}`))
|
||||
);
|
||||
}
|
||||
|
||||
list(): Observable<SaleCategory[]> {
|
||||
const options = {params: new HttpParams().set('l', '')};
|
||||
return <Observable<SaleCategory[]>>this.http.get<SaleCategory[]>(url, options)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'list'))
|
||||
);
|
||||
}
|
||||
|
||||
save(saleCategory: SaleCategory): Observable<SaleCategory> {
|
||||
return <Observable<SaleCategory>>this.http.post<SaleCategory>(`${url}/new`, saleCategory, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'save'))
|
||||
);
|
||||
}
|
||||
|
||||
update(saleCategory: SaleCategory): Observable<SaleCategory> {
|
||||
return <Observable<SaleCategory>>this.http.put<SaleCategory>(`${url}/${saleCategory.id}`, saleCategory, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'update'))
|
||||
);
|
||||
}
|
||||
|
||||
updateSortOrder(list: SaleCategory[]): Observable<boolean> {
|
||||
return <Observable<boolean>>this.http.post<SaleCategory[]>(url, list, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'updateSortOrder'))
|
||||
);
|
||||
}
|
||||
|
||||
saveOrUpdate(saleCategory: SaleCategory): Observable<SaleCategory> {
|
||||
if (!saleCategory.id) {
|
||||
return this.save(saleCategory);
|
||||
} else {
|
||||
return this.update(saleCategory);
|
||||
}
|
||||
}
|
||||
|
||||
delete(id: string): Observable<SaleCategory> {
|
||||
return <Observable<SaleCategory>>this.http.delete<SaleCategory>(`${url}/${id}`, httpOptions)
|
||||
.pipe(
|
||||
catchError(this.log.handleError(serviceName, 'delete'))
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user