forked from Yara724/api
Merge pull request 'Fix expert identity case search' (#341) from s.yahyaee/yara724-api:main into main
Reviewed-on: Yara724/api#341
This commit is contained in:
@@ -798,12 +798,16 @@ export class ExpertClaimService {
|
||||
nationalCode: party?.person?.nationalCode,
|
||||
nationalCodeOfInsurer: party?.person?.nationalCodeOfInsurer,
|
||||
nationalCodeOfDriver: party?.person?.nationalCodeOfDriver,
|
||||
inquiryParticipants: Array.isArray(party?.inquiryParticipants)
|
||||
? party.inquiryParticipants.map((participant: any) => ({
|
||||
participants: (
|
||||
Array.isArray(party?.participants)
|
||||
? party.participants
|
||||
: party?.inquiryParticipants
|
||||
)?.map((participant: any) => ({
|
||||
phoneNumber: participant?.phoneNumber,
|
||||
nationalCode: participant?.nationalCode,
|
||||
}))
|
||||
: undefined,
|
||||
nationalCodeOfInsurer: participant?.nationalCodeOfInsurer,
|
||||
nationalCodeOfDriver: participant?.nationalCodeOfDriver,
|
||||
})),
|
||||
}));
|
||||
}
|
||||
if (blameRequestType !== BlameRequestType.CAR_BODY) return out;
|
||||
|
||||
@@ -35,9 +35,15 @@ describe("applyListQueryV2", () => {
|
||||
parties: [
|
||||
{
|
||||
person: {
|
||||
phoneNumber: "0912-123-4567",
|
||||
phoneNumber: "+98 912 123 4567",
|
||||
nationalCodeOfDriver: "۰۰۱۲۳۴۵۶۷۸",
|
||||
},
|
||||
participants: [
|
||||
{
|
||||
phoneNumber: "0913-765-4321",
|
||||
nationalCode: "۰۰۹۸۷۶۵۴۳۲۱",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
@@ -55,7 +61,7 @@ describe("applyListQueryV2", () => {
|
||||
};
|
||||
|
||||
const byPhone = applyListQueryV2(identityRows, identityGetters, {
|
||||
phoneNumber: "09121234567",
|
||||
phoneNumber: "۰۹۱۲۱۲۳۴۵۶۷",
|
||||
});
|
||||
expect(byPhone.list.map((row) => row.publicId)).toEqual(["PHONE"]);
|
||||
|
||||
@@ -63,6 +69,16 @@ describe("applyListQueryV2", () => {
|
||||
nationalCode: "0012345678",
|
||||
});
|
||||
expect(byNationalCode.list.map((row) => row.publicId)).toEqual(["PHONE"]);
|
||||
|
||||
const byParticipantPhone = applyListQueryV2(identityRows, identityGetters, {
|
||||
phoneNumber: "09137654321",
|
||||
});
|
||||
expect(byParticipantPhone.list.map((row) => row.publicId)).toEqual(["PHONE"]);
|
||||
|
||||
const byParticipantNationalCode = applyListQueryV2(identityRows, identityGetters, {
|
||||
nationalCode: "۰۰۹۸۷۶۵۴۳۲۱",
|
||||
});
|
||||
expect(byParticipantNationalCode.list.map((row) => row.publicId)).toEqual(["PHONE"]);
|
||||
});
|
||||
|
||||
it("sorts by publicId ascending", () => {
|
||||
|
||||
@@ -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),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -6636,12 +6636,16 @@ export class RequestManagementService {
|
||||
nationalCode: entry?.person?.nationalCode,
|
||||
nationalCodeOfInsurer: entry?.person?.nationalCodeOfInsurer,
|
||||
nationalCodeOfDriver: entry?.person?.nationalCodeOfDriver,
|
||||
inquiryParticipants: Array.isArray(entry?.inquiryParticipants)
|
||||
? entry.inquiryParticipants.map((participant: any) => ({
|
||||
participants: (
|
||||
Array.isArray(entry?.participants)
|
||||
? entry.participants
|
||||
: entry?.inquiryParticipants
|
||||
)?.map((participant: any) => ({
|
||||
phoneNumber: participant?.phoneNumber,
|
||||
nationalCode: participant?.nationalCode,
|
||||
}))
|
||||
: undefined,
|
||||
nationalCodeOfInsurer: participant?.nationalCodeOfInsurer,
|
||||
nationalCodeOfDriver: participant?.nationalCodeOfDriver,
|
||||
})),
|
||||
}))
|
||||
: [];
|
||||
|
||||
|
||||
Reference in New Issue
Block a user