Refactored customer discount and choose discount. They were using the same schema unnecessarily which was leading to confusion.
This commit is contained in:
@ -39,6 +39,7 @@
|
||||
<mat-label>Discount on {{ r.name }}</mat-label>
|
||||
<input matInput formControlName="discount" />
|
||||
<span matSuffix>%</span>
|
||||
<mat-hint>Max {{ r.limit | percent : '1.2-2' }}</mat-hint>
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -131,7 +131,7 @@ export class CustomerDetailComponent implements OnInit, AfterViewInit {
|
||||
if (array_item && array_item?.discount) {
|
||||
item.discount = Math.max(Math.min(round(array_item.discount / 100, 5), 100), 0);
|
||||
} else {
|
||||
item.discount = null;
|
||||
item.discount = 0;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -1,18 +0,0 @@
|
||||
import { inject, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { CustomerDiscountsService } from './customer-discounts.service';
|
||||
|
||||
describe('CustomerDiscountsService', () => {
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [CustomerDiscountsService],
|
||||
});
|
||||
});
|
||||
|
||||
it('should be created', inject(
|
||||
[CustomerDiscountsService],
|
||||
(service: CustomerDiscountsService) => {
|
||||
expect(service).toBeTruthy();
|
||||
},
|
||||
));
|
||||
});
|
||||
@ -1,34 +0,0 @@
|
||||
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 '../sales/discount/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 }[]
|
||||
>;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user