forked from Yara724/api
YARA-1257, YARA-1272, YARA-985
This commit is contained in:
@@ -2526,7 +2526,7 @@ export class ClaimRequestManagementService {
|
||||
/**
|
||||
* V2 response mapper:
|
||||
* - convert factorLink ObjectId -> public URL
|
||||
* - enrich daghi.branchId with branchName when available
|
||||
* - enrich legacy daghi.branchId with branchName when available
|
||||
*/
|
||||
private async mapEvaluationForClient(
|
||||
evaluation: any,
|
||||
@@ -3381,29 +3381,17 @@ export class ClaimRequestManagementService {
|
||||
return updated.objection;
|
||||
}
|
||||
|
||||
async inPersonVisit(requestId: string, branchId: string, actorDetail: any) {
|
||||
async inPersonVisit(requestId: string, actorDetail: any) {
|
||||
const request =
|
||||
await this.claimRequestManagementDbService.findOne(requestId);
|
||||
if (!request) {
|
||||
throw new NotFoundException("Claim not found");
|
||||
}
|
||||
|
||||
const branch = await this.branchDbService.findById(branchId);
|
||||
if (!branch) {
|
||||
throw new NotFoundException(`Branch with ID ${branchId} not found.`);
|
||||
}
|
||||
|
||||
if (String(request.userClientKey) !== String(branch.clientKey)) {
|
||||
throw new ForbiddenException(
|
||||
"This branch does not belong to the insurer of this claim.",
|
||||
);
|
||||
}
|
||||
|
||||
const updated = await this.claimRequestManagementDbService.findAndUpdate(
|
||||
requestId,
|
||||
{
|
||||
claimStatus: ReqClaimStatus.InPersonVisit,
|
||||
visitLocation: `Branch ${branch.name} at ${branch.address}`,
|
||||
},
|
||||
);
|
||||
|
||||
@@ -3523,27 +3511,6 @@ export class ClaimRequestManagementService {
|
||||
return amount > 0 ? amount : FANAVARAN_PROVISIONAL_ESTIMATE_AMOUNT;
|
||||
}
|
||||
|
||||
/** Branch ids referenced on expert-priced parts (`daghi` object with `branchId`). */
|
||||
private collectBranchIdsFromClaimExpertReply(reply: {
|
||||
parts?: unknown[];
|
||||
}): Set<string> {
|
||||
const ids = new Set<string>();
|
||||
const parts = reply?.parts;
|
||||
if (!Array.isArray(parts)) {
|
||||
return ids;
|
||||
}
|
||||
for (const p of parts) {
|
||||
const d = (p as { daghi?: unknown })?.daghi;
|
||||
if (d && typeof d === "object" && d !== null && "branchId" in d) {
|
||||
const bid = (d as { branchId?: unknown }).branchId;
|
||||
if (bid != null && Types.ObjectId.isValid(String(bid))) {
|
||||
ids.add(String(bid));
|
||||
}
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
}
|
||||
|
||||
private getTejaratnoFanavaranConfig() {
|
||||
return {
|
||||
appName: this.APP_NAME,
|
||||
@@ -11012,7 +10979,6 @@ export class ClaimRequestManagementService {
|
||||
async submitOwnerInsurerApprovalSignV2(
|
||||
claimRequestId: string,
|
||||
agree: boolean,
|
||||
branchId: string,
|
||||
signFile: Express.Multer.File,
|
||||
currentUserId: string,
|
||||
actor?: { sub: string; role?: string; fullName?: string },
|
||||
@@ -11072,12 +11038,6 @@ export class ClaimRequestManagementService {
|
||||
}
|
||||
|
||||
const shape = classifyV2ExpertPricingParts(active.parts ?? []);
|
||||
const pricedBranchReply = {
|
||||
parts: (active.parts ?? []).filter(
|
||||
(p: { factorNeeded?: boolean }) => !p.factorNeeded,
|
||||
),
|
||||
};
|
||||
|
||||
const isMixedPartialGate =
|
||||
shape.mixedFactorAndPrice &&
|
||||
claimCase.claimStatus === ClaimStatus.NEEDS_REVISION &&
|
||||
@@ -11112,39 +11072,6 @@ export class ClaimRequestManagementService {
|
||||
);
|
||||
}
|
||||
|
||||
const rawBranchId = (branchId ?? "").trim();
|
||||
if (!rawBranchId || !Types.ObjectId.isValid(rawBranchId)) {
|
||||
throw new BadRequestException(
|
||||
"branchId is required and must be a valid MongoDB ObjectId.",
|
||||
);
|
||||
}
|
||||
const branchDoc = await this.branchDbService.findById(rawBranchId);
|
||||
if (!branchDoc) {
|
||||
throw new NotFoundException(`Branch with ID ${rawBranchId} not found.`);
|
||||
}
|
||||
const ownerClientId = claimCase.owner?.clientId;
|
||||
if (
|
||||
!ownerClientId ||
|
||||
String(branchDoc.clientKey) !== String(ownerClientId)
|
||||
) {
|
||||
throw new ForbiddenException(
|
||||
"This branch does not belong to the insurer for this claim.",
|
||||
);
|
||||
}
|
||||
const branchIdsOnPricing = isMixedPartialGate
|
||||
? this.collectBranchIdsFromClaimExpertReply(pricedBranchReply)
|
||||
: this.collectBranchIdsFromClaimExpertReply(
|
||||
active as { parts?: unknown[] },
|
||||
);
|
||||
if (
|
||||
branchIdsOnPricing.size > 0 &&
|
||||
!branchIdsOnPricing.has(String(rawBranchId))
|
||||
) {
|
||||
throw new BadRequestException(
|
||||
"branchId must match a branch used in the expert pricing for this claim.",
|
||||
);
|
||||
}
|
||||
|
||||
const signDoc = await this.claimSignDbService.create({
|
||||
fileName: signFile.filename,
|
||||
userId: effectiveUserId,
|
||||
@@ -11155,7 +11082,6 @@ export class ClaimRequestManagementService {
|
||||
const signedAt = new Date();
|
||||
const scopedApprovalPayload = {
|
||||
agree,
|
||||
branchId: new Types.ObjectId(rawBranchId),
|
||||
signDetailId: signId,
|
||||
signedAt,
|
||||
};
|
||||
@@ -11181,7 +11107,7 @@ export class ClaimRequestManagementService {
|
||||
type: "OWNER_REJECTED_PRICED_PARTS_BEFORE_FACTORS",
|
||||
actor: historyActor,
|
||||
timestamp: signedAt,
|
||||
metadata: { branchId: rawBranchId },
|
||||
metadata: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -11210,7 +11136,7 @@ export class ClaimRequestManagementService {
|
||||
type: "OWNER_SIGNED_PRICED_PARTS_PENDING_FACTOR_UPLOAD",
|
||||
actor: historyActor,
|
||||
timestamp: signedAt,
|
||||
metadata: { branchId: rawBranchId },
|
||||
metadata: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -11241,7 +11167,7 @@ export class ClaimRequestManagementService {
|
||||
type: "OWNER_REJECTED_INSURER_APPROVAL_PRICING",
|
||||
actor: historyActor,
|
||||
timestamp: signedAt,
|
||||
metadata: { branchId: rawBranchId },
|
||||
metadata: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
@@ -11275,7 +11201,7 @@ export class ClaimRequestManagementService {
|
||||
type: "OWNER_SIGNED_INSURER_APPROVAL",
|
||||
actor: historyActor,
|
||||
timestamp: signedAt,
|
||||
metadata: { branchId: rawBranchId },
|
||||
metadata: {},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user