forked from Yara724/api
Merge pull request 'YARA-1201, YARA-1147' (#246) from s.yahyaee/yara724-api:main into main
Reviewed-on: Yara724/api#246
This commit is contained in:
@@ -93,6 +93,28 @@ export class FileMakerBlameV4Controller {
|
||||
);
|
||||
}
|
||||
|
||||
@Get("my-files")
|
||||
@ApiOperation({
|
||||
summary: "List all blame files created by this FileMaker",
|
||||
description: "Returns all V4 FileMaker blame files initiated by the authenticated FileMaker.",
|
||||
})
|
||||
async getMyFiles(@CurrentUser() fileMaker: any) {
|
||||
return this.requestManagementService.getMyFileMakerFiles(fileMaker);
|
||||
}
|
||||
|
||||
@Get("my-files/:requestId")
|
||||
@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.",
|
||||
})
|
||||
async getMyFileDetail(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() fileMaker: any,
|
||||
) {
|
||||
return this.requestManagementService.getMyFileMakerFileDetail(fileMaker, requestId);
|
||||
}
|
||||
|
||||
@Get("claim-id/:requestId")
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@ApiOperation({
|
||||
|
||||
@@ -92,6 +92,28 @@ export class FileMakerBlameV5Controller {
|
||||
);
|
||||
}
|
||||
|
||||
@Get("my-files")
|
||||
@ApiOperation({
|
||||
summary: "List all blame files created by this FileMaker",
|
||||
description: "Returns all V5 FileMaker blame files initiated by the authenticated FileMaker.",
|
||||
})
|
||||
async getMyFiles(@CurrentUser() fileMaker: any) {
|
||||
return this.requestManagementService.getMyFileMakerFiles(fileMaker);
|
||||
}
|
||||
|
||||
@Get("my-files/:requestId")
|
||||
@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.",
|
||||
})
|
||||
async getMyFileDetail(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() fileMaker: any,
|
||||
) {
|
||||
return this.requestManagementService.getMyFileMakerFileDetail(fileMaker, requestId);
|
||||
}
|
||||
|
||||
@Get("claim-id/:requestId")
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@ApiOperation({
|
||||
|
||||
@@ -84,6 +84,28 @@ export class FileReviewerBlameV4Controller {
|
||||
|
||||
// ─── Linked claim lookup ──────────────────────────────────────────────────────
|
||||
|
||||
@Get("my-files")
|
||||
@ApiOperation({
|
||||
summary: "List all blame files assigned to this FileReviewer",
|
||||
description: "Returns all V4 FileMaker blame files that have been assigned to the authenticated FileReviewer.",
|
||||
})
|
||||
async getMyFiles(@CurrentUser() fileReviewer: any) {
|
||||
return this.requestManagementService.getMyFileReviewerFiles(fileReviewer);
|
||||
}
|
||||
|
||||
@Get("my-files/:requestId")
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@ApiOperation({
|
||||
summary: "Get a single blame file assigned to this FileReviewer",
|
||||
description: "Returns full detail — parties, workflow, expert fields, linked claim ID — for one V4 blame file.",
|
||||
})
|
||||
async getMyFileDetail(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() fileReviewer: any,
|
||||
) {
|
||||
return this.requestManagementService.getMyFileReviewerFileDetail(fileReviewer, requestId);
|
||||
}
|
||||
|
||||
@Get("claim-id/:requestId")
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@ApiOperation({
|
||||
|
||||
@@ -82,6 +82,28 @@ export class FileReviewerBlameV5Controller {
|
||||
|
||||
// ─── Linked claim lookup ──────────────────────────────────────────────────────
|
||||
|
||||
@Get("my-files")
|
||||
@ApiOperation({
|
||||
summary: "List all blame files assigned to this FileReviewer",
|
||||
description: "Returns all V5 FileMaker blame files that have been assigned to the authenticated FileReviewer.",
|
||||
})
|
||||
async getMyFiles(@CurrentUser() fileReviewer: any) {
|
||||
return this.requestManagementService.getMyFileReviewerFiles(fileReviewer);
|
||||
}
|
||||
|
||||
@Get("my-files/:requestId")
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@ApiOperation({
|
||||
summary: "Get a single blame file assigned to this FileReviewer",
|
||||
description: "Returns full detail — parties, workflow, expert fields, linked claim ID — for one V5 blame file.",
|
||||
})
|
||||
async getMyFileDetail(
|
||||
@Param("requestId") requestId: string,
|
||||
@CurrentUser() fileReviewer: any,
|
||||
) {
|
||||
return this.requestManagementService.getMyFileReviewerFileDetail(fileReviewer, requestId);
|
||||
}
|
||||
|
||||
@Get("claim-id/:requestId")
|
||||
@ApiParam({ name: "requestId", description: "Blame request ID" })
|
||||
@ApiOperation({
|
||||
|
||||
@@ -11039,6 +11039,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