forked from Yara724/api
fix: align inquiry errors and expert review rules
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
import { BlameRequestType } from "src/Types&Enums/blame-request-management/blameRequestType.enum";
|
||||
import { CaseStatus } from "src/Types&Enums/blame-request-management/caseStatus.enum";
|
||||
import { ExpertBlameService } from "./expert-blame.service";
|
||||
|
||||
describe("ExpertBlameService participant detail contract", () => {
|
||||
it("returns normalized participants and their role assignments from the blame party", async () => {
|
||||
const service = new (ExpertBlameService as any)(
|
||||
...new Array(13).fill(undefined),
|
||||
) as any;
|
||||
const expertId = "66ec0e480e321873c0900001";
|
||||
|
||||
service.expireBlameCaseWorkflowLockV2IfStale = jest
|
||||
.fn()
|
||||
.mockResolvedValue(undefined);
|
||||
service.blameRequestDbService = {
|
||||
findByIdWithoutHistory: jest.fn().mockResolvedValue({
|
||||
_id: "66ec0e480e321873c0900002",
|
||||
type: BlameRequestType.THIRD_PARTY,
|
||||
status: CaseStatus.WAITING_FOR_EXPERT,
|
||||
expertInitiated: true,
|
||||
initiatedByFieldExpertId: expertId,
|
||||
workflow: {},
|
||||
parties: [
|
||||
{
|
||||
role: "FIRST",
|
||||
person: { fullName: "Legacy Party Name" },
|
||||
participants: [
|
||||
{
|
||||
participantId: "PERSON_1",
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
unknown: true,
|
||||
},
|
||||
],
|
||||
participantRoles: {
|
||||
driver: "PERSON_1",
|
||||
vehicleOwner: "PERSON_1",
|
||||
thirdPartyPolicyholder: "PERSON_1",
|
||||
},
|
||||
vehicle: { inquiry: { raw: { large: true } } },
|
||||
},
|
||||
],
|
||||
createdAt: new Date("2026-09-19T00:00:00.000Z"),
|
||||
updatedAt: new Date("2026-09-19T00:00:00.000Z"),
|
||||
}),
|
||||
};
|
||||
|
||||
const result = await service.findOneV2("blame-1", { sub: expertId });
|
||||
const party = (result.parties as any[])[0];
|
||||
|
||||
expect(party.participants).toEqual([
|
||||
{
|
||||
participantId: "PERSON_1",
|
||||
nationalCode: "0012345678",
|
||||
birthday: "1370/01/01",
|
||||
},
|
||||
]);
|
||||
expect(party.participantRoles).toEqual({
|
||||
driver: "PERSON_1",
|
||||
vehicleOwner: "PERSON_1",
|
||||
thirdPartyPolicyholder: "PERSON_1",
|
||||
});
|
||||
expect(party.person.fullName).toBe("Legacy Party Name");
|
||||
expect(party.vehicle.inquiry).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -91,6 +91,7 @@ import {
|
||||
ExpertFileActivityType,
|
||||
ExpertFileKind,
|
||||
} from "src/users/entities/schema/expert-file-activity.schema";
|
||||
import { sanitizeStoredInquiryParticipants } from "src/request-management/inquiry-participant-resolver";
|
||||
|
||||
interface CheckedRequestEntry {
|
||||
CheckedRequest?: {
|
||||
@@ -1250,8 +1251,17 @@ export class ExpertBlameService {
|
||||
doc.createdAtFormatted = `${createdDate} ${createdTime}`;
|
||||
doc.updatedAtFormatted = `${updatedDate} ${updatedTime}`;
|
||||
|
||||
// Keep the normalized blame-party participant contract authoritative for
|
||||
// every expert detail response. Legacy person fields remain for old files,
|
||||
// but new UIs must read participants + participantRoles from the same party.
|
||||
doc.parties = parties.map((party: Record<string, unknown>) => ({
|
||||
...party,
|
||||
participants: sanitizeStoredInquiryParticipants(party.participants),
|
||||
participantRoles: party.participantRoles,
|
||||
}));
|
||||
|
||||
// Strip heavy SandHub inquiry blob
|
||||
for (const party of parties as Array<{
|
||||
for (const party of doc.parties as Array<{
|
||||
vehicle?: Record<string, unknown>;
|
||||
}>) {
|
||||
if (
|
||||
|
||||
Reference in New Issue
Block a user