DB Normalization: Moved fractionUnits back to Product from SKU as it is better suited there.
Feature: Created the ProductSku schema for the product/sku autocomplete
This commit is contained in:
@@ -5,6 +5,7 @@ import { catchError } from 'rxjs/operators';
|
||||
|
||||
import { ErrorLoggerService } from '../core/error-logger.service';
|
||||
import { Product } from '../core/product';
|
||||
import { ProductSku } from '../core/product-sku';
|
||||
|
||||
const url = '/api/products';
|
||||
const serviceName = 'ProductService';
|
||||
@@ -51,16 +52,28 @@ export class ProductService {
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'delete'))) as Observable<Product>;
|
||||
}
|
||||
|
||||
autocomplete(
|
||||
autocompleteProduct(query: string, isPurchased: boolean | null): Observable<ProductSku[]> {
|
||||
const options = {
|
||||
params: new HttpParams().set('q', query),
|
||||
};
|
||||
if (isPurchased !== null) {
|
||||
options.params = options.params.set('p', isPurchased.toString());
|
||||
}
|
||||
return this.http
|
||||
.get<ProductSku[]>(`${url}/q-product`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable<
|
||||
ProductSku[]
|
||||
>;
|
||||
}
|
||||
|
||||
autocompleteSku(
|
||||
query: string,
|
||||
isPurchased: boolean | null,
|
||||
extended: boolean = false,
|
||||
skus: boolean = true,
|
||||
date?: string,
|
||||
vendorId?: string,
|
||||
): Observable<Product[]> {
|
||||
): Observable<ProductSku[]> {
|
||||
const options = {
|
||||
params: new HttpParams().set('q', query).set('e', extended.toString()).set('s', skus),
|
||||
params: new HttpParams().set('q', query),
|
||||
};
|
||||
if (isPurchased !== null) {
|
||||
options.params = options.params.set('p', isPurchased.toString());
|
||||
@@ -69,7 +82,9 @@ export class ProductService {
|
||||
options.params = options.params.set('v', vendorId as string).set('d', date as string);
|
||||
}
|
||||
return this.http
|
||||
.get<Product[]>(`${url}/query`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable<Product[]>;
|
||||
.get<ProductSku[]>(`${url}/q-sku`, options)
|
||||
.pipe(catchError(this.log.handleError(serviceName, 'autocomplete'))) as Observable<
|
||||
ProductSku[]
|
||||
>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user