forked from Yara724/api
Fix expert identity case search
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import type { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
import { BadRequestException } from "@nestjs/common";
|
||||
import { normalizeIranMobile } from "src/helpers/iran-mobile";
|
||||
|
||||
const MAX_LIMIT = 100;
|
||||
const DEFAULT_LIMIT_WHEN_PAGE_SET = 20;
|
||||
@@ -69,6 +70,11 @@ function isNationalCodeKey(key: string): boolean {
|
||||
return /national[_-]?(code|id)|code[_-]?mell?i|mell?i[_-]?code/i.test(key);
|
||||
}
|
||||
|
||||
function normalizePhoneSearchValue(raw: unknown): string {
|
||||
const digits = normalizeIdentityValue(raw);
|
||||
return normalizeIranMobile(digits) ?? digits;
|
||||
}
|
||||
|
||||
function collectIdentityValues(
|
||||
value: unknown,
|
||||
matchKey: (key: string) => boolean,
|
||||
@@ -117,7 +123,7 @@ export function applyListQueryV2<T>(
|
||||
totalPages?: number;
|
||||
} {
|
||||
const search = normalizeSearch(query.search);
|
||||
const phoneNumber = normalizeIdentityValue(query.phoneNumber);
|
||||
const phoneNumber = normalizePhoneSearchValue(query.phoneNumber);
|
||||
const nationalCode = normalizeIdentityValue(query.nationalCode);
|
||||
let filtered = rows;
|
||||
if (query.fileType && getters.fileType) {
|
||||
@@ -128,7 +134,7 @@ export function applyListQueryV2<T>(
|
||||
if (phoneNumber) {
|
||||
filtered = filtered.filter((row) =>
|
||||
collectIdentityValues(row, isPhoneKey).some((value) =>
|
||||
value.includes(phoneNumber),
|
||||
normalizePhoneSearchValue(value).includes(phoneNumber),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user