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,
|
nationalCode: party?.person?.nationalCode,
|
||||||
nationalCodeOfInsurer: party?.person?.nationalCodeOfInsurer,
|
nationalCodeOfInsurer: party?.person?.nationalCodeOfInsurer,
|
||||||
nationalCodeOfDriver: party?.person?.nationalCodeOfDriver,
|
nationalCodeOfDriver: party?.person?.nationalCodeOfDriver,
|
||||||
inquiryParticipants: Array.isArray(party?.inquiryParticipants)
|
participants: (
|
||||||
? party.inquiryParticipants.map((participant: any) => ({
|
Array.isArray(party?.participants)
|
||||||
phoneNumber: participant?.phoneNumber,
|
? party.participants
|
||||||
nationalCode: participant?.nationalCode,
|
: party?.inquiryParticipants
|
||||||
}))
|
)?.map((participant: any) => ({
|
||||||
: undefined,
|
phoneNumber: participant?.phoneNumber,
|
||||||
|
nationalCode: participant?.nationalCode,
|
||||||
|
nationalCodeOfInsurer: participant?.nationalCodeOfInsurer,
|
||||||
|
nationalCodeOfDriver: participant?.nationalCodeOfDriver,
|
||||||
|
})),
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
if (blameRequestType !== BlameRequestType.CAR_BODY) return out;
|
if (blameRequestType !== BlameRequestType.CAR_BODY) return out;
|
||||||
|
|||||||
@@ -35,9 +35,15 @@ describe("applyListQueryV2", () => {
|
|||||||
parties: [
|
parties: [
|
||||||
{
|
{
|
||||||
person: {
|
person: {
|
||||||
phoneNumber: "0912-123-4567",
|
phoneNumber: "+98 912 123 4567",
|
||||||
nationalCodeOfDriver: "۰۰۱۲۳۴۵۶۷۸",
|
nationalCodeOfDriver: "۰۰۱۲۳۴۵۶۷۸",
|
||||||
},
|
},
|
||||||
|
participants: [
|
||||||
|
{
|
||||||
|
phoneNumber: "0913-765-4321",
|
||||||
|
nationalCode: "۰۰۹۸۷۶۵۴۳۲۱",
|
||||||
|
},
|
||||||
|
],
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
@@ -55,7 +61,7 @@ describe("applyListQueryV2", () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const byPhone = applyListQueryV2(identityRows, identityGetters, {
|
const byPhone = applyListQueryV2(identityRows, identityGetters, {
|
||||||
phoneNumber: "09121234567",
|
phoneNumber: "۰۹۱۲۱۲۳۴۵۶۷",
|
||||||
});
|
});
|
||||||
expect(byPhone.list.map((row) => row.publicId)).toEqual(["PHONE"]);
|
expect(byPhone.list.map((row) => row.publicId)).toEqual(["PHONE"]);
|
||||||
|
|
||||||
@@ -63,6 +69,16 @@ describe("applyListQueryV2", () => {
|
|||||||
nationalCode: "0012345678",
|
nationalCode: "0012345678",
|
||||||
});
|
});
|
||||||
expect(byNationalCode.list.map((row) => row.publicId)).toEqual(["PHONE"]);
|
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", () => {
|
it("sorts by publicId ascending", () => {
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import type { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
import type { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||||
import { BadRequestException } from "@nestjs/common";
|
import { BadRequestException } from "@nestjs/common";
|
||||||
|
import { normalizeIranMobile } from "src/helpers/iran-mobile";
|
||||||
|
|
||||||
const MAX_LIMIT = 100;
|
const MAX_LIMIT = 100;
|
||||||
const DEFAULT_LIMIT_WHEN_PAGE_SET = 20;
|
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);
|
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(
|
function collectIdentityValues(
|
||||||
value: unknown,
|
value: unknown,
|
||||||
matchKey: (key: string) => boolean,
|
matchKey: (key: string) => boolean,
|
||||||
@@ -117,7 +123,7 @@ export function applyListQueryV2<T>(
|
|||||||
totalPages?: number;
|
totalPages?: number;
|
||||||
} {
|
} {
|
||||||
const search = normalizeSearch(query.search);
|
const search = normalizeSearch(query.search);
|
||||||
const phoneNumber = normalizeIdentityValue(query.phoneNumber);
|
const phoneNumber = normalizePhoneSearchValue(query.phoneNumber);
|
||||||
const nationalCode = normalizeIdentityValue(query.nationalCode);
|
const nationalCode = normalizeIdentityValue(query.nationalCode);
|
||||||
let filtered = rows;
|
let filtered = rows;
|
||||||
if (query.fileType && getters.fileType) {
|
if (query.fileType && getters.fileType) {
|
||||||
@@ -128,7 +134,7 @@ export function applyListQueryV2<T>(
|
|||||||
if (phoneNumber) {
|
if (phoneNumber) {
|
||||||
filtered = filtered.filter((row) =>
|
filtered = filtered.filter((row) =>
|
||||||
collectIdentityValues(row, isPhoneKey).some((value) =>
|
collectIdentityValues(row, isPhoneKey).some((value) =>
|
||||||
value.includes(phoneNumber),
|
normalizePhoneSearchValue(value).includes(phoneNumber),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6636,12 +6636,16 @@ export class RequestManagementService {
|
|||||||
nationalCode: entry?.person?.nationalCode,
|
nationalCode: entry?.person?.nationalCode,
|
||||||
nationalCodeOfInsurer: entry?.person?.nationalCodeOfInsurer,
|
nationalCodeOfInsurer: entry?.person?.nationalCodeOfInsurer,
|
||||||
nationalCodeOfDriver: entry?.person?.nationalCodeOfDriver,
|
nationalCodeOfDriver: entry?.person?.nationalCodeOfDriver,
|
||||||
inquiryParticipants: Array.isArray(entry?.inquiryParticipants)
|
participants: (
|
||||||
? entry.inquiryParticipants.map((participant: any) => ({
|
Array.isArray(entry?.participants)
|
||||||
phoneNumber: participant?.phoneNumber,
|
? entry.participants
|
||||||
nationalCode: participant?.nationalCode,
|
: entry?.inquiryParticipants
|
||||||
}))
|
)?.map((participant: any) => ({
|
||||||
: undefined,
|
phoneNumber: participant?.phoneNumber,
|
||||||
|
nationalCode: participant?.nationalCode,
|
||||||
|
nationalCodeOfInsurer: participant?.nationalCodeOfInsurer,
|
||||||
|
nationalCodeOfDriver: participant?.nationalCodeOfDriver,
|
||||||
|
})),
|
||||||
}))
|
}))
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user