forked from Yara724/api
YARA-1201, YARA-1147
This commit is contained in:
@@ -11023,6 +11023,193 @@ export class RequestManagementService {
|
||||
/**
|
||||
* V6: List blame files created by this call-center agent.
|
||||
*/
|
||||
// ─── FileMaker file list / detail (V4 + V5) ────────────────────────────────
|
||||
|
||||
async getMyFileMakerFiles(fileMaker: any): Promise<any[]> {
|
||||
if (fileMaker?.role !== RoleEnum.FILE_MAKER) {
|
||||
throw new ForbiddenException("Only FileMakers can use this endpoint.");
|
||||
}
|
||||
const makerId = new Types.ObjectId(fileMaker.sub);
|
||||
const files = await this.blameRequestDbService.find({
|
||||
isMadeByFileMaker: true,
|
||||
initiatedByFieldExpertId: makerId,
|
||||
});
|
||||
return (files || []).map((f: any) => ({
|
||||
_id: f._id,
|
||||
publicId: f.publicId,
|
||||
requestNo: f.requestNo,
|
||||
type: f.type,
|
||||
status: f.status,
|
||||
blameStatus: f.blameStatus,
|
||||
workflow: {
|
||||
currentStep: f.workflow?.currentStep,
|
||||
nextStep: f.workflow?.nextStep,
|
||||
completedSteps: f.workflow?.completedSteps,
|
||||
},
|
||||
requiresFileMakerApproval: f.requiresFileMakerApproval,
|
||||
createdAt: f.createdAt,
|
||||
updatedAt: f.updatedAt,
|
||||
}));
|
||||
}
|
||||
|
||||
async getMyFileMakerFileDetail(fileMaker: any, requestId: string): Promise<any> {
|
||||
if (fileMaker?.role !== RoleEnum.FILE_MAKER) {
|
||||
throw new ForbiddenException("Only FileMakers can use this endpoint.");
|
||||
}
|
||||
const req = await this.blameRequestDbService.findById(requestId);
|
||||
if (!req) throw new NotFoundException("Blame request not found");
|
||||
if (
|
||||
!req.isMadeByFileMaker ||
|
||||
String((req as any).initiatedByFieldExpertId) !== String(fileMaker.sub)
|
||||
) {
|
||||
throw new ForbiddenException("You can only access files that you have created.");
|
||||
}
|
||||
const plain = typeof (req as any).toObject === "function"
|
||||
? (req as any).toObject({ versionKey: false })
|
||||
: { ...(req as any) };
|
||||
// Attach linked claim ID if present
|
||||
const claim = await this.claimCaseDbService.findOne({ blameRequestId: (req as any)._id });
|
||||
return {
|
||||
_id: plain._id,
|
||||
publicId: plain.publicId,
|
||||
requestNo: plain.requestNo,
|
||||
type: plain.type,
|
||||
status: plain.status,
|
||||
blameStatus: plain.blameStatus,
|
||||
workflow: plain.workflow,
|
||||
requiresFileMakerApproval: plain.requiresFileMakerApproval,
|
||||
parties: (plain.parties ?? []).map((p: any) => ({
|
||||
role: p.role,
|
||||
person: {
|
||||
phoneNumber: p.person?.phoneNumber,
|
||||
nationalCodeOfInsurer: p.person?.nationalCodeOfInsurer,
|
||||
nationalCodeOfDriver: p.person?.nationalCodeOfDriver,
|
||||
driverIsInsurer: p.person?.driverIsInsurer,
|
||||
userId: p.person?.userId ? String(p.person.userId) : undefined,
|
||||
clientId: p.person?.clientId ? String(p.person.clientId) : undefined,
|
||||
},
|
||||
insurance: p.insurance ? {
|
||||
company: p.insurance.company,
|
||||
policyNumber: p.insurance.policyNumber,
|
||||
startDate: p.insurance.startDate,
|
||||
endDate: p.insurance.endDate,
|
||||
financialCeiling: p.insurance.financialCeiling,
|
||||
} : undefined,
|
||||
vehicle: p.vehicle ? {
|
||||
plateId: p.vehicle.plateId,
|
||||
name: p.vehicle.name,
|
||||
type: p.vehicle.type,
|
||||
} : undefined,
|
||||
inquiryComplete: !!(p.person?.inquiriesCompleted),
|
||||
hasSigned: p.confirmation != null,
|
||||
})),
|
||||
linkedClaimId: claim ? String((claim as any)._id) : null,
|
||||
createdAt: plain.createdAt,
|
||||
updatedAt: plain.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
// ─── FileReviewer file list / detail (V4 + V5) ─────────────────────────────
|
||||
|
||||
async getMyFileReviewerFiles(fileReviewer: any): Promise<any[]> {
|
||||
if (fileReviewer?.role !== RoleEnum.FILE_REVIEWER) {
|
||||
throw new ForbiddenException("Only FileReviewers can use this endpoint.");
|
||||
}
|
||||
const reviewerId = new Types.ObjectId(fileReviewer.sub);
|
||||
const files = await this.blameRequestDbService.find({
|
||||
isMadeByFileMaker: true,
|
||||
assignedFileReviewerId: reviewerId,
|
||||
});
|
||||
return (files || []).map((f: any) => ({
|
||||
_id: f._id,
|
||||
publicId: f.publicId,
|
||||
requestNo: f.requestNo,
|
||||
type: f.type,
|
||||
status: f.status,
|
||||
blameStatus: f.blameStatus,
|
||||
workflow: {
|
||||
currentStep: f.workflow?.currentStep,
|
||||
nextStep: f.workflow?.nextStep,
|
||||
completedSteps: f.workflow?.completedSteps,
|
||||
},
|
||||
requiresFileMakerApproval: f.requiresFileMakerApproval,
|
||||
createdAt: f.createdAt,
|
||||
updatedAt: f.updatedAt,
|
||||
}));
|
||||
}
|
||||
|
||||
async getMyFileReviewerFileDetail(fileReviewer: any, requestId: string): Promise<any> {
|
||||
if (fileReviewer?.role !== RoleEnum.FILE_REVIEWER) {
|
||||
throw new ForbiddenException("Only FileReviewers can use this endpoint.");
|
||||
}
|
||||
const req = await this.blameRequestDbService.findById(requestId);
|
||||
if (!req) throw new NotFoundException("Blame request not found");
|
||||
if (!req.isMadeByFileMaker) {
|
||||
throw new ForbiddenException("FileReviewer can only access V4/V5 FileMaker files.");
|
||||
}
|
||||
const assignedId = (req as any).assignedFileReviewerId
|
||||
? String((req as any).assignedFileReviewerId)
|
||||
: null;
|
||||
if (assignedId && assignedId !== String(fileReviewer.sub)) {
|
||||
throw new ForbiddenException("This file has been taken by another FileReviewer.");
|
||||
}
|
||||
const plain = typeof (req as any).toObject === "function"
|
||||
? (req as any).toObject({ versionKey: false })
|
||||
: { ...(req as any) };
|
||||
const claim = await this.claimCaseDbService.findOne({ blameRequestId: (req as any)._id });
|
||||
return {
|
||||
_id: plain._id,
|
||||
publicId: plain.publicId,
|
||||
requestNo: plain.requestNo,
|
||||
type: plain.type,
|
||||
status: plain.status,
|
||||
blameStatus: plain.blameStatus,
|
||||
workflow: plain.workflow,
|
||||
requiresFileMakerApproval: plain.requiresFileMakerApproval,
|
||||
assignedFileReviewerId: plain.assignedFileReviewerId
|
||||
? String(plain.assignedFileReviewerId)
|
||||
: null,
|
||||
parties: (plain.parties ?? []).map((p: any) => ({
|
||||
role: p.role,
|
||||
person: {
|
||||
phoneNumber: p.person?.phoneNumber,
|
||||
nationalCodeOfInsurer: p.person?.nationalCodeOfInsurer,
|
||||
nationalCodeOfDriver: p.person?.nationalCodeOfDriver,
|
||||
driverIsInsurer: p.person?.driverIsInsurer,
|
||||
userId: p.person?.userId ? String(p.person.userId) : undefined,
|
||||
clientId: p.person?.clientId ? String(p.person.clientId) : undefined,
|
||||
},
|
||||
insurance: p.insurance ? {
|
||||
company: p.insurance.company,
|
||||
policyNumber: p.insurance.policyNumber,
|
||||
startDate: p.insurance.startDate,
|
||||
endDate: p.insurance.endDate,
|
||||
financialCeiling: p.insurance.financialCeiling,
|
||||
} : undefined,
|
||||
vehicle: p.vehicle ? {
|
||||
plateId: p.vehicle.plateId,
|
||||
name: p.vehicle.name,
|
||||
type: p.vehicle.type,
|
||||
} : undefined,
|
||||
inquiryComplete: !!(p.person?.inquiriesCompleted),
|
||||
hasSigned: p.confirmation != null,
|
||||
})),
|
||||
expert: plain.expert ? {
|
||||
decision: plain.expert.decision ? {
|
||||
guiltyPartyId: plain.expert.decision.guiltyPartyId
|
||||
? String(plain.expert.decision.guiltyPartyId)
|
||||
: undefined,
|
||||
description: plain.expert.decision.description,
|
||||
decidedAt: plain.expert.decision.decidedAt,
|
||||
} : undefined,
|
||||
accidentFields: plain.expert.accidentFields,
|
||||
} : undefined,
|
||||
linkedClaimId: claim ? String((claim as any)._id) : null,
|
||||
createdAt: plain.createdAt,
|
||||
updatedAt: plain.updatedAt,
|
||||
};
|
||||
}
|
||||
|
||||
async getMyCallCenterFilesV6(agent: any): Promise<any[]> {
|
||||
if (agent?.role !== RoleEnum.CALL_CENTER) {
|
||||
throw new ForbiddenException("Only call-center agents can use this endpoint.");
|
||||
|
||||
Reference in New Issue
Block a user