mirror of
https://dev.azure.com/hugendubel/ISA/_git/ISA-Frontend
synced 2025-12-31 09:37:15 +01:00
Merged PR 281: #913 Update RegEx to spot customer card numbers
& allow for customer card numbers with spaces
This commit is contained in:
@@ -4,13 +4,18 @@ import { BranchSelectors } from 'apps/sales/src/app/core/store/selectors/branch.
|
||||
import { Observable, NEVER } from 'rxjs';
|
||||
import { switchMap, map, take, catchError } from 'rxjs/operators';
|
||||
import { CollectingShelfService } from 'apps/sales/src/app/core/services/collecting-shelf.service';
|
||||
import { AutocompleteTokenDTO, ResponseArgsOfIEnumerableOfAutocompleteDTO } from '@swagger/oms/lib';
|
||||
import {
|
||||
AutocompleteTokenDTO,
|
||||
ResponseArgsOfIEnumerableOfAutocompleteDTO,
|
||||
} from '@swagger/oms/lib';
|
||||
import { SearchStateFacade } from '@shelf-store';
|
||||
import { CustomerService } from '@sales/core-services';
|
||||
|
||||
@Injectable({ providedIn: 'root' })
|
||||
export class ShelfSearchFacadeService {
|
||||
@Select(BranchSelectors.getUserBranch) currentUserBranchId$: Observable<string>;
|
||||
@Select(BranchSelectors.getUserBranch) currentUserBranchId$: Observable<
|
||||
string
|
||||
>;
|
||||
|
||||
constructor(
|
||||
private readonly customerService: CustomerService,
|
||||
@@ -47,9 +52,12 @@ export class ShelfSearchFacadeService {
|
||||
allowCustomerCardSearch: true,
|
||||
}
|
||||
) {
|
||||
const searchQuery = await this.getSearchQuery(this.getBarcodeSearchQuery(barcode), {
|
||||
allowCustomerCardSearch: options.allowCustomerCardSearch,
|
||||
});
|
||||
const searchQuery = await this.getSearchQuery(
|
||||
this.getBarcodeSearchQuery(barcode),
|
||||
{
|
||||
allowCustomerCardSearch: options.allowCustomerCardSearch,
|
||||
}
|
||||
);
|
||||
|
||||
if (!this.isValidSearchQuery(searchQuery)) {
|
||||
return;
|
||||
@@ -59,13 +67,18 @@ export class ShelfSearchFacadeService {
|
||||
return this.requestSearch(true);
|
||||
}
|
||||
|
||||
searchForAutocomplete(queryString: string, options: { selectedFilters?: { [key: string]: string } } = {}) {
|
||||
searchForAutocomplete(
|
||||
queryString: string,
|
||||
options: { selectedFilters?: { [key: string]: string } } = {}
|
||||
) {
|
||||
const searchQuery = queryString.trim();
|
||||
const autoCompleteQuery: AutocompleteTokenDTO = this.generateAutocompleteToken({
|
||||
queryString: searchQuery,
|
||||
filter: options.selectedFilters || {},
|
||||
take: 5,
|
||||
});
|
||||
const autoCompleteQuery: AutocompleteTokenDTO = this.generateAutocompleteToken(
|
||||
{
|
||||
queryString: searchQuery,
|
||||
filter: options.selectedFilters || {},
|
||||
take: 5,
|
||||
}
|
||||
);
|
||||
|
||||
if (!this.isValidSearchQuery(searchQuery)) {
|
||||
return NEVER;
|
||||
@@ -78,7 +91,10 @@ export class ShelfSearchFacadeService {
|
||||
return this.searchStateFacade.fetchResult({ isNewSearch });
|
||||
}
|
||||
|
||||
private getSearchQuery(queryString: string, options: { allowCustomerCardSearch: boolean }): Promise<string> {
|
||||
private getSearchQuery(
|
||||
queryString: string,
|
||||
options: { allowCustomerCardSearch: boolean }
|
||||
): Promise<string> {
|
||||
if (options.allowCustomerCardSearch && this.isCustomerCard(queryString)) {
|
||||
return this.getCustomerNumber(queryString);
|
||||
}
|
||||
@@ -100,8 +116,16 @@ export class ShelfSearchFacadeService {
|
||||
};
|
||||
}
|
||||
|
||||
private requestAutocompleteSearch(autocompleteToken: AutocompleteTokenDTO): Observable<ResponseArgsOfIEnumerableOfAutocompleteDTO> {
|
||||
return this.currentUserBranchId$.pipe(switchMap(() => this.collectingShelfService.searchWarenausgabeAutocomplete(autocompleteToken)));
|
||||
private requestAutocompleteSearch(
|
||||
autocompleteToken: AutocompleteTokenDTO
|
||||
): Observable<ResponseArgsOfIEnumerableOfAutocompleteDTO> {
|
||||
return this.currentUserBranchId$.pipe(
|
||||
switchMap(() =>
|
||||
this.collectingShelfService.searchWarenausgabeAutocomplete(
|
||||
autocompleteToken
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private isValidSearchQuery(queryString: string): boolean {
|
||||
@@ -113,16 +137,18 @@ export class ShelfSearchFacadeService {
|
||||
}
|
||||
|
||||
private isCustomerCard(queryString: string): boolean {
|
||||
const regExp = /^(?=.*\d)(?=.*[A-Z])[A-Z0-9]{8,12}$/;
|
||||
return regExp.test(queryString);
|
||||
const regExp = /^(?=.*\d)(?=.*[A-Z])[A-Z0-9]{8,12}$/gi;
|
||||
return regExp.test(queryString.trim());
|
||||
}
|
||||
|
||||
private getCustomerNumber(customerCardNumber: string): Promise<string> {
|
||||
return this.customerService
|
||||
.searchCustomer(customerCardNumber)
|
||||
.searchCustomer(customerCardNumber.trim())
|
||||
.pipe(
|
||||
map((response) => response.customers),
|
||||
map((customers) => (customers[0] ? customers[0].customerNumber : customerCardNumber)),
|
||||
map((customers) =>
|
||||
customers[0] ? customers[0].customerNumber : customerCardNumber
|
||||
),
|
||||
catchError(() => customerCardNumber),
|
||||
take(1)
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user