forked from Yara724/api
feat: manage expert access and merge Parsian expert seeds
Allow role-specific identities and admin account activation, support national-code-only claim experts, and remove required voice from v4/v5. Add a combined, resumable Parsian seed that preserves existing accounts and merges locations and product codes.
This commit is contained in:
@@ -10,6 +10,133 @@ import { ClaimCaseStatus } from "src/Types&Enums/claim-request-management/claim-
|
||||
import { ClaimWorkflowStep } from "src/Types&Enums/claim-request-management/claim-workflow-steps.enum";
|
||||
|
||||
describe("RequestManagementService V4 FileMaker workflow", () => {
|
||||
it.each([
|
||||
[4, BlameRequestType.CAR_BODY],
|
||||
[4, BlameRequestType.THIRD_PARTY],
|
||||
[5, BlameRequestType.CAR_BODY],
|
||||
[5, BlameRequestType.THIRD_PARTY],
|
||||
])(
|
||||
"completes v%s %s narratives and signatures without voice",
|
||||
async (flow, type) => {
|
||||
const actor = {
|
||||
sub: String(new Types.ObjectId()),
|
||||
role: RoleEnum.FILE_MAKER,
|
||||
};
|
||||
const request: any = {
|
||||
_id: new Types.ObjectId(),
|
||||
type,
|
||||
expertInitiated: true,
|
||||
isMadeByFileMaker: true,
|
||||
requiresFileMakerApproval: flow === 5,
|
||||
initiatedByFieldExpertId: new Types.ObjectId(actor.sub),
|
||||
creationMethod: CreationMethod.IN_PERSON,
|
||||
status: CaseStatus.OPEN,
|
||||
parties: [
|
||||
PartyRole.FIRST,
|
||||
...(type === BlameRequestType.THIRD_PARTY ? [PartyRole.SECOND] : []),
|
||||
].map((role) => ({
|
||||
role,
|
||||
person: { userId: new Types.ObjectId() },
|
||||
evidence: {},
|
||||
})),
|
||||
workflow: {
|
||||
currentStep: WorkflowStep.FIRST_INITIAL_FORM,
|
||||
completedSteps: [],
|
||||
},
|
||||
history: [],
|
||||
save: jest.fn().mockResolvedValue(undefined),
|
||||
};
|
||||
const service: any = new (RequestManagementService as any)();
|
||||
service.verifyExpertAccessForBlameV2 = jest
|
||||
.fn()
|
||||
.mockResolvedValue(undefined);
|
||||
service.blameRequestDbService = {
|
||||
findById: async () => request,
|
||||
findByIdAndUpdate: async (_id, update) => {
|
||||
for (const [key, value] of Object.entries(update.$set)) {
|
||||
const [, index] = key.split(".");
|
||||
request.parties[Number(index)].confirmation = value;
|
||||
}
|
||||
},
|
||||
};
|
||||
service.userSign = {
|
||||
create: jest.fn(async () => ({ _id: new Types.ObjectId() })),
|
||||
};
|
||||
service.blameVoiceDbService = { create: jest.fn() };
|
||||
for (const party of request.parties) {
|
||||
service.markPartyInquiriesCompleteOnBlame(request, party.role, actor);
|
||||
const prefix = party.role === PartyRole.FIRST ? "FIRST" : "SECOND";
|
||||
expect(request.workflow.currentStep).toBe(`${prefix}_DESCRIPTION`);
|
||||
const description = {
|
||||
desc: "شرح حادثه ".repeat(15),
|
||||
accidentDate: "2025-01-01",
|
||||
accidentTime: "10:30",
|
||||
};
|
||||
if (flow === 4)
|
||||
await service.addPartyDescriptionV4(
|
||||
String(request._id),
|
||||
actor,
|
||||
description,
|
||||
party.role,
|
||||
);
|
||||
else
|
||||
await service.addPartyDescriptionV3(
|
||||
String(request._id),
|
||||
actor,
|
||||
description,
|
||||
party.role,
|
||||
);
|
||||
expect(request.workflow.currentStep).toBe(`${prefix}_SIGN`);
|
||||
await service.expertUploadPartySignatureV3(
|
||||
actor,
|
||||
String(request._id),
|
||||
party.role,
|
||||
true,
|
||||
{ filename: "signature.png", path: "files/signature.png" },
|
||||
);
|
||||
expect(party.confirmation.accepted).toBe(true);
|
||||
expect(request.workflow.completedSteps).not.toContain(
|
||||
`${prefix}_VOICE`,
|
||||
);
|
||||
}
|
||||
expect(service.blameVoiceDbService.create).not.toHaveBeenCalled();
|
||||
expect(request.workflow.currentStep).toBe(
|
||||
type === BlameRequestType.CAR_BODY
|
||||
? WorkflowStep.FIRST_COMPLETED
|
||||
: WorkflowStep.SECOND_COMPLETED,
|
||||
);
|
||||
},
|
||||
);
|
||||
|
||||
it.each([WorkflowStep.FIRST_VOICE, WorkflowStep.SECOND_VOICE])(
|
||||
"repairs legacy %s resume values without erasing existing recordings or history",
|
||||
(step) => {
|
||||
const service: any = new (RequestManagementService as any)();
|
||||
const file = {
|
||||
workflow: {
|
||||
currentStep: step,
|
||||
nextStep: step.replace("VOICE", "DESCRIPTION"),
|
||||
completedSteps: [step],
|
||||
},
|
||||
parties: [{ evidence: { voices: ["existing-recording"] } }],
|
||||
history: [{ type: "V3_PARTY_VOICE_UPLOADED" }],
|
||||
};
|
||||
const before = JSON.stringify(file);
|
||||
expect(service.fileMakerWorkflowProjection(file).currentStep).toBe(
|
||||
step.replace("VOICE", "DESCRIPTION"),
|
||||
);
|
||||
expect(service.fileMakerWorkflowProjection(file).nextStep).toBe(step.replace("VOICE", "SIGN"));
|
||||
expect(JSON.stringify(file)).toBe(before);
|
||||
},
|
||||
);
|
||||
|
||||
it("keeps voice in the non-FileMaker in-person inquiry workflow", () => {
|
||||
const service: any = new (RequestManagementService as any)();
|
||||
const request: any = { workflow: { completedSteps: [] }, parties: [] };
|
||||
service.markPartyInquiriesCompleteOnBlame(request, PartyRole.FIRST, {});
|
||||
expect(request.workflow.currentStep).toBe(WorkflowStep.FIRST_LOCATION);
|
||||
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_VOICE);
|
||||
});
|
||||
it("persists FIRST_INITIAL_FORM after the first party OTP is verified", async () => {
|
||||
const fileMakerId = new Types.ObjectId();
|
||||
const userId = new Types.ObjectId();
|
||||
@@ -87,7 +214,7 @@ describe("RequestManagementService V4 FileMaker workflow", () => {
|
||||
|
||||
expect(request.workflow.currentStep).toBe(WorkflowStep.FIRST_INITIAL_FORM);
|
||||
expect(request.workflow.currentStep).not.toBe(WorkflowStep.FIRST_VIDEO);
|
||||
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_VOICE);
|
||||
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_DESCRIPTION);
|
||||
expect(request.workflow.completedSteps).not.toContain(
|
||||
WorkflowStep.FIRST_VIDEO,
|
||||
);
|
||||
@@ -169,7 +296,7 @@ describe("RequestManagementService V4 FileMaker workflow", () => {
|
||||
);
|
||||
|
||||
expect(request.workflow.currentStep).toBe(WorkflowStep.FIRST_INITIAL_FORM);
|
||||
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_VOICE);
|
||||
expect(request.workflow.nextStep).toBe(WorkflowStep.FIRST_DESCRIPTION);
|
||||
expect(request.workflow.completedSteps).not.toContain(
|
||||
WorkflowStep.FIRST_VIDEO,
|
||||
);
|
||||
@@ -212,7 +339,7 @@ describe("RequestManagementService V4 FileMaker workflow", () => {
|
||||
expect(reopened.workflow).toEqual(
|
||||
expect.objectContaining({
|
||||
currentStep: WorkflowStep.FIRST_INITIAL_FORM,
|
||||
nextStep: WorkflowStep.FIRST_VOICE,
|
||||
nextStep: WorkflowStep.FIRST_DESCRIPTION,
|
||||
}),
|
||||
);
|
||||
expect(reopened.workflow.completedSteps).not.toContain(
|
||||
|
||||
@@ -31,7 +31,10 @@ import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { CreationMethod } from "./entities/schema/request-management.schema";
|
||||
import { CreateExpertInitiatedFileDto } from "./dto/expert-initiated.dto";
|
||||
import { SendPartyOtpDto, VerifyPartyOtpDto } from "./dto/party-otp.dto";
|
||||
import { RunInquiriesV3Dto, RunInquiriesVinV3Dto } from "./dto/run-inquiries-v3.dto";
|
||||
import {
|
||||
RunInquiriesV3Dto,
|
||||
RunInquiriesVinV3Dto,
|
||||
} from "./dto/run-inquiries-v3.dto";
|
||||
import {
|
||||
CarBodyFormDto,
|
||||
DescriptionV4Dto,
|
||||
@@ -57,11 +60,11 @@ import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
* THIRD_PARTY sequence:
|
||||
* create → send-party-otp (guilty) → verify-party-otp (guilty)
|
||||
* → [car-body-form if CAR_BODY] → run-inquiries (guilty + auto claim)
|
||||
* → add-detail-location / add-detail-description / upload-voice (guilty)
|
||||
* → add-detail-description (voice optional) (guilty)
|
||||
* → sign (guilty)
|
||||
* → send-party-otp (damaged) → verify-party-otp (damaged)
|
||||
* → run-inquiries (damaged)
|
||||
* → add-detail-location / add-detail-description / upload-voice (damaged)
|
||||
* → add-detail-description (voice optional) (damaged)
|
||||
* → sign (damaged) ← FileMaker job done here
|
||||
*
|
||||
* CAR_BODY sequence: same but single party — omit second-party steps.
|
||||
@@ -91,14 +94,19 @@ export class FileMakerBlameV4Controller {
|
||||
fileMaker,
|
||||
// requiresFileMakerApproval is V5-only; explicitly exclude it from V4 so
|
||||
// a client that accidentally sends the field cannot poison the blame record.
|
||||
{ ...dto, creationMethod: CreationMethod.IN_PERSON, requiresFileMakerApproval: false },
|
||||
{
|
||||
...dto,
|
||||
creationMethod: CreationMethod.IN_PERSON,
|
||||
requiresFileMakerApproval: false,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@Get("my-files")
|
||||
@ApiOperation({
|
||||
summary: "List all blame files created by this FileMaker",
|
||||
description: "Returns V4 FileMaker blame files using the shared search, sort, filter, and pagination query contract.",
|
||||
description:
|
||||
"Returns V4 FileMaker blame files using the shared search, sort, filter, and pagination query contract.",
|
||||
})
|
||||
async getMyFiles(
|
||||
@CurrentUser() fileMaker: any,
|
||||
@@ -111,13 +119,17 @@ export class FileMakerBlameV4Controller {
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@ApiOperation({
|
||||
summary: "Get a single blame file created by this FileMaker",
|
||||
description: "Returns full detail — parties, workflow, linked claim ID — for one V4 FileMaker blame file.",
|
||||
description:
|
||||
"Returns full detail — parties, workflow, linked claim ID — for one V4 FileMaker blame file.",
|
||||
})
|
||||
async getMyFileDetail(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() fileMaker: any,
|
||||
) {
|
||||
return this.requestManagementService.getMyFileMakerFileDetail(fileMaker, requestId);
|
||||
return this.requestManagementService.getMyFileMakerFileDetail(
|
||||
fileMaker,
|
||||
requestId,
|
||||
);
|
||||
}
|
||||
|
||||
@Get("claim-id/:requestId")
|
||||
@@ -312,7 +324,7 @@ export class FileMakerBlameV4Controller {
|
||||
)
|
||||
@Post("upload-voice/:requestId")
|
||||
@ApiParam({ name: "requestId" })
|
||||
@ApiOperation({ summary: "Upload voice for current party" })
|
||||
@ApiOperation({ summary: "Upload optional voice for current party" })
|
||||
async uploadVoice(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() fileMaker: any,
|
||||
|
||||
@@ -31,7 +31,10 @@ import { RoleEnum } from "src/Types&Enums/role.enum";
|
||||
import { CreationMethod } from "./entities/schema/request-management.schema";
|
||||
import { CreateExpertInitiatedFileDto } from "./dto/expert-initiated.dto";
|
||||
import { SendPartyOtpDto, VerifyPartyOtpDto } from "./dto/party-otp.dto";
|
||||
import { RunInquiriesV3Dto, RunInquiriesVinV3Dto } from "./dto/run-inquiries-v3.dto";
|
||||
import {
|
||||
RunInquiriesV3Dto,
|
||||
RunInquiriesVinV3Dto,
|
||||
} from "./dto/run-inquiries-v3.dto";
|
||||
import {
|
||||
CarBodyFormDto,
|
||||
DescriptionDto,
|
||||
@@ -60,11 +63,11 @@ import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||
* THIRD_PARTY sequence:
|
||||
* create → send-party-otp (guilty) → verify-party-otp (guilty)
|
||||
* → [car-body-form if CAR_BODY] → run-inquiries (guilty + auto claim)
|
||||
* → add-detail-location / add-detail-description / upload-voice (guilty)
|
||||
* → add-detail-description (voice optional) (guilty)
|
||||
* → sign (guilty)
|
||||
* → send-party-otp (damaged) → verify-party-otp (damaged)
|
||||
* → run-inquiries (damaged)
|
||||
* → add-detail-location / add-detail-description / upload-voice (damaged)
|
||||
* → add-detail-description (voice optional) (damaged)
|
||||
* → sign (damaged) ← FileMaker job done here
|
||||
*/
|
||||
@ApiTags("v5 FileMaker — blame file creation (with FinancialExpert approval)")
|
||||
@@ -90,14 +93,19 @@ export class FileMakerBlameV5Controller {
|
||||
) {
|
||||
return this.requestManagementService.createExpertInitiatedBlameV2(
|
||||
fileMaker,
|
||||
{ ...dto, creationMethod: CreationMethod.IN_PERSON, requiresFileMakerApproval: true },
|
||||
{
|
||||
...dto,
|
||||
creationMethod: CreationMethod.IN_PERSON,
|
||||
requiresFileMakerApproval: true,
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@Get("my-files")
|
||||
@ApiOperation({
|
||||
summary: "List all blame files created by this FileMaker",
|
||||
description: "Returns V5 FileMaker blame files using the shared search, sort, filter, and pagination query contract.",
|
||||
description:
|
||||
"Returns V5 FileMaker blame files using the shared search, sort, filter, and pagination query contract.",
|
||||
})
|
||||
async getMyFiles(
|
||||
@CurrentUser() fileMaker: any,
|
||||
@@ -110,13 +118,17 @@ export class FileMakerBlameV5Controller {
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@ApiOperation({
|
||||
summary: "Get a single blame file created by this FileMaker",
|
||||
description: "Returns full detail — parties, workflow, linked claim ID — for one V5 FileMaker blame file.",
|
||||
description:
|
||||
"Returns full detail — parties, workflow, linked claim ID — for one V5 FileMaker blame file.",
|
||||
})
|
||||
async getMyFileDetail(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() fileMaker: any,
|
||||
) {
|
||||
return this.requestManagementService.getMyFileMakerFileDetail(fileMaker, requestId);
|
||||
return this.requestManagementService.getMyFileMakerFileDetail(
|
||||
fileMaker,
|
||||
requestId,
|
||||
);
|
||||
}
|
||||
|
||||
@Get("claim-id/:requestId")
|
||||
@@ -306,7 +318,7 @@ export class FileMakerBlameV5Controller {
|
||||
)
|
||||
@Post("upload-voice/:requestId")
|
||||
@ApiParam({ name: "requestId" })
|
||||
@ApiOperation({ summary: "Upload voice for current party" })
|
||||
@ApiOperation({ summary: "Upload optional voice for current party" })
|
||||
async uploadVoice(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() fileMaker: any,
|
||||
|
||||
@@ -4261,7 +4261,7 @@ export class RequestManagementService {
|
||||
if (isFileMakerFlow) {
|
||||
advancedTo = WorkflowStep.FIRST_INITIAL_FORM;
|
||||
req.workflow.currentStep = advancedTo;
|
||||
req.workflow.nextStep = WorkflowStep.FIRST_VOICE;
|
||||
req.workflow.nextStep = WorkflowStep.FIRST_DESCRIPTION;
|
||||
} else {
|
||||
const step3 = await this.getWorkflowStep({ stepNumber: 3 }); // FIRST_VIDEO
|
||||
advancedTo = step3.stepKey as WorkflowStep;
|
||||
@@ -7089,10 +7089,10 @@ export class RequestManagementService {
|
||||
: [WorkflowStep.CREATED, WorkflowStep.FIRST_INITIAL_FORM];
|
||||
this.pushWorkflowSteps(req, completedSteps);
|
||||
req.workflow.currentStep = skipLocation
|
||||
? WorkflowStep.FIRST_VOICE
|
||||
? WorkflowStep.FIRST_DESCRIPTION
|
||||
: WorkflowStep.FIRST_LOCATION;
|
||||
req.workflow.nextStep = skipLocation
|
||||
? WorkflowStep.FIRST_DESCRIPTION
|
||||
? WorkflowStep.FIRST_SIGN
|
||||
: WorkflowStep.FIRST_VOICE;
|
||||
|
||||
const firstIdx = this.getPartyIndex(req, PartyRole.FIRST);
|
||||
@@ -7113,14 +7113,28 @@ export class RequestManagementService {
|
||||
: [WorkflowStep.SECOND_INITIAL_FORM];
|
||||
this.pushWorkflowSteps(req, completedSteps);
|
||||
req.workflow.currentStep = skipLocation
|
||||
? WorkflowStep.SECOND_VOICE
|
||||
? WorkflowStep.SECOND_DESCRIPTION
|
||||
: WorkflowStep.SECOND_LOCATION;
|
||||
req.workflow.nextStep = skipLocation
|
||||
? WorkflowStep.SECOND_DESCRIPTION
|
||||
? WorkflowStep.SECOND_SIGN
|
||||
: WorkflowStep.SECOND_VOICE;
|
||||
}
|
||||
}
|
||||
|
||||
private completeFileMakerPartyDescription(req: any, role: PartyRole): void {
|
||||
if (!req.isMadeByFileMaker) return;
|
||||
const firstParty = role === PartyRole.FIRST;
|
||||
this.pushWorkflowSteps(req, [
|
||||
firstParty ? WorkflowStep.FIRST_DESCRIPTION : WorkflowStep.SECOND_DESCRIPTION,
|
||||
]);
|
||||
req.workflow.currentStep = firstParty
|
||||
? WorkflowStep.FIRST_SIGN
|
||||
: WorkflowStep.SECOND_SIGN;
|
||||
req.workflow.nextStep = firstParty
|
||||
? WorkflowStep.FIRST_COMPLETED
|
||||
: WorkflowStep.SECOND_COMPLETED;
|
||||
}
|
||||
|
||||
private async createV3ClaimFromBlame(
|
||||
req: any,
|
||||
actor: any,
|
||||
@@ -8109,7 +8123,7 @@ export class RequestManagementService {
|
||||
if (partyRole === PartyRole.FIRST) {
|
||||
this.pushWorkflowSteps(fresh, [
|
||||
WorkflowStep.FIRST_LOCATION,
|
||||
WorkflowStep.FIRST_VOICE,
|
||||
...(isFileMakerActor ? [] : [WorkflowStep.FIRST_VOICE]),
|
||||
WorkflowStep.FIRST_DESCRIPTION,
|
||||
WorkflowStep.FIRST_SIGN,
|
||||
WorkflowStep.FIRST_COMPLETED,
|
||||
@@ -8127,7 +8141,7 @@ export class RequestManagementService {
|
||||
} else {
|
||||
this.pushWorkflowSteps(fresh, [
|
||||
WorkflowStep.SECOND_LOCATION,
|
||||
WorkflowStep.SECOND_VOICE,
|
||||
...(isFileMakerActor ? [] : [WorkflowStep.SECOND_VOICE]),
|
||||
WorkflowStep.SECOND_DESCRIPTION,
|
||||
WorkflowStep.SECOND_SIGN,
|
||||
WorkflowStep.SECOND_COMPLETED,
|
||||
@@ -8559,6 +8573,8 @@ export class RequestManagementService {
|
||||
metadata: { partyRole: role },
|
||||
} as any);
|
||||
|
||||
this.completeFileMakerPartyDescription(req, role);
|
||||
|
||||
await (req as any).save();
|
||||
return { requestId: req._id, publicId: req.publicId, partyRole: role };
|
||||
}
|
||||
@@ -8630,6 +8646,8 @@ export class RequestManagementService {
|
||||
},
|
||||
} as any);
|
||||
|
||||
this.completeFileMakerPartyDescription(req, role);
|
||||
|
||||
await (req as any).save();
|
||||
return { requestId: req._id, publicId: req.publicId, partyRole: role };
|
||||
}
|
||||
@@ -8670,7 +8688,7 @@ export class RequestManagementService {
|
||||
this.pushWorkflowSteps(req, [WorkflowStep.CAR_BODY_ACCIDENT_TYPE]);
|
||||
if ((req as any).isMadeByFileMaker) {
|
||||
req.workflow.currentStep = WorkflowStep.FIRST_INITIAL_FORM;
|
||||
req.workflow.nextStep = WorkflowStep.FIRST_VOICE;
|
||||
req.workflow.nextStep = WorkflowStep.FIRST_DESCRIPTION;
|
||||
} else {
|
||||
req.workflow.currentStep = WorkflowStep.CAR_BODY_ACCIDENT_TYPE;
|
||||
req.workflow.nextStep = WorkflowStep.FIRST_INITIAL_FORM;
|
||||
@@ -9678,7 +9696,7 @@ export class RequestManagementService {
|
||||
return {
|
||||
...workflow,
|
||||
currentStep: WorkflowStep.FIRST_INITIAL_FORM,
|
||||
nextStep: WorkflowStep.FIRST_VOICE,
|
||||
nextStep: WorkflowStep.FIRST_DESCRIPTION,
|
||||
completedSteps,
|
||||
};
|
||||
}
|
||||
@@ -9695,7 +9713,18 @@ export class RequestManagementService {
|
||||
};
|
||||
}
|
||||
|
||||
return { ...workflow, completedSteps };
|
||||
const withoutVoice = (step: WorkflowStep) => {
|
||||
if (step === WorkflowStep.FIRST_VOICE) return WorkflowStep.FIRST_DESCRIPTION;
|
||||
if (step === WorkflowStep.SECOND_VOICE) return WorkflowStep.SECOND_DESCRIPTION;
|
||||
return step;
|
||||
};
|
||||
const currentStep = withoutVoice(workflow.currentStep);
|
||||
let nextStep = withoutVoice(workflow.nextStep);
|
||||
if (currentStep === WorkflowStep.FIRST_DESCRIPTION && nextStep === currentStep)
|
||||
nextStep = WorkflowStep.FIRST_SIGN;
|
||||
if (currentStep === WorkflowStep.SECOND_DESCRIPTION && nextStep === currentStep)
|
||||
nextStep = WorkflowStep.SECOND_SIGN;
|
||||
return { ...workflow, currentStep, nextStep, completedSteps };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user