mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
#1405 bugfix search customer via customer card number (scan)
This commit is contained in:
@@ -51,6 +51,10 @@ export class CrmCustomerService {
|
||||
});
|
||||
}
|
||||
|
||||
getCustomersByCustomerCardNumber(queryString: string): Observable<PagedResult<CustomerInfoDTO>> {
|
||||
return this.customerService.CustomerGetCustomerByBonuscard(!!queryString ? queryString : undefined);
|
||||
}
|
||||
|
||||
getCustomer(customerId: number, eagerLoading?: number): Observable<Result<CustomerDTO>> {
|
||||
return this.customerService.CustomerGetCustomer({ customerId, eagerLoading });
|
||||
}
|
||||
|
||||
@@ -330,10 +330,81 @@ export abstract class CustomerSearch implements OnInit, OnDestroy {
|
||||
)
|
||||
.subscribe((result) => {
|
||||
this.setQuery(result.data);
|
||||
this.search();
|
||||
// this.search();
|
||||
this.searchCustomerCard();
|
||||
});
|
||||
}
|
||||
|
||||
searchCustomerCard(
|
||||
options: { isNewSearch: boolean; take?: number } = {
|
||||
isNewSearch: true,
|
||||
take: 10,
|
||||
}
|
||||
): void {
|
||||
if (!this.shouldFetchNewProducts(options)) {
|
||||
return; // early exit because no new products need to be fetched
|
||||
}
|
||||
if (this.searchState !== 'fetching') {
|
||||
this.searchState$.next('fetching');
|
||||
|
||||
this.searchResult$
|
||||
.pipe(
|
||||
take(1),
|
||||
switchMap(() => {
|
||||
return this.customerSearch.getCustomersByCustomerCardNumber(this.queryFilter.query).pipe(
|
||||
takeUntil(this.destroy$),
|
||||
catchError((err: HttpErrorResponse) => {
|
||||
return of<PagedResult<CustomerInfoDTO>>({
|
||||
result: [],
|
||||
error: true,
|
||||
hits: 0,
|
||||
message: err.message,
|
||||
});
|
||||
}),
|
||||
tap((result) => {
|
||||
if (result.error) {
|
||||
this.searchState$.next('error');
|
||||
} else if (result.hits === 0) {
|
||||
this.searchState$.next('empty');
|
||||
} else {
|
||||
this.searchState$.next('result');
|
||||
}
|
||||
})
|
||||
);
|
||||
})
|
||||
)
|
||||
.subscribe((r) => {
|
||||
const hits = r.hits || r.result.length;
|
||||
|
||||
this.searchResult$.next(this.removeLoadingProducts(this.searchResult));
|
||||
if (options.isNewSearch) {
|
||||
this.searchResult$.next({
|
||||
...r,
|
||||
hits,
|
||||
result: r.result.map((a) => ({ ...a, loaded: true })),
|
||||
});
|
||||
if (this.searchState === 'result') {
|
||||
if (hits === 1) {
|
||||
this.navigateToDetails(r.result[0].id);
|
||||
} else {
|
||||
this.navigateToResults();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.searchResult$.next({
|
||||
...r,
|
||||
hits,
|
||||
result: [...this.searchResult$.value.result, ...r.result.map((a) => ({ ...a, loaded: true }))],
|
||||
});
|
||||
}
|
||||
|
||||
if (hits > 0) {
|
||||
this.filterActive$.next(false);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
navigateToDetails(customerId: number) {
|
||||
this.router.navigate(['customer', customerId]);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user