36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { HttpClient } from '@angular/common/http';
|
|
import { Injectable } from '@angular/core';
|
|
import { Observable } from 'rxjs';
|
|
import { catchError } from 'rxjs/operators';
|
|
|
|
import { ErrorLoggerService } from '../../core/error-logger.service';
|
|
|
|
import { DiscountItem } from './discount-item';
|
|
|
|
const url = '/api/customer-discounts';
|
|
const serviceName = 'CustomerService';
|
|
|
|
@Injectable({
|
|
providedIn: 'root',
|
|
})
|
|
export class CustomerDiscountsService {
|
|
constructor(private http: HttpClient, private log: ErrorLoggerService) {}
|
|
|
|
list(id: string | undefined): Observable<DiscountItem[]> {
|
|
const getUrl: string = id === undefined ? `${url}` : `${url}/${id}`;
|
|
return this.http
|
|
.get<DiscountItem[]>(getUrl)
|
|
.pipe(catchError(this.log.handleError(serviceName, `get id=${id}`))) as Observable<
|
|
DiscountItem[]
|
|
>;
|
|
}
|
|
|
|
listForDiscount(): Observable<{ name: string; discount: number; discountLimit: number }[]> {
|
|
return this.http
|
|
.get<{ name: string; discount: number; discountLimit: number }[]>(`${url}/for-discount`)
|
|
.pipe(catchError(this.log.handleError(serviceName, 'list'))) as Observable<
|
|
{ name: string; discount: number; discountLimit: number }[]
|
|
>;
|
|
}
|
|
}
|