forked from Yara724/api
location dynamicallllllly finally or not ?
This commit is contained in:
@@ -3367,46 +3367,35 @@ export class ClaimRequestManagementService {
|
||||
/**
|
||||
* Fanavaran HTTP Location from assigned staff `locations[].id`
|
||||
* (file-maker / file-reviewer / field / blame / damage expert), for every
|
||||
* tenant. Falls back to tenant auth.location only when no staff location is set.
|
||||
* tenant. Prefer the claim creator, then the originating file's staff.
|
||||
* Missing staff configuration must not submit a claim to a default branch.
|
||||
*/
|
||||
private async resolveFanavaranLocationForClaim(
|
||||
claimCaseId: string,
|
||||
clientKey: FanavaranClientKey,
|
||||
): Promise<string> {
|
||||
const defaultLocation = getFanavaranClientProfile(clientKey).auth.location;
|
||||
|
||||
try {
|
||||
const claimCase = await this.claimCaseDbService.findById(claimCaseId);
|
||||
if (!claimCase?.blameRequestId) {
|
||||
return defaultLocation;
|
||||
}
|
||||
|
||||
const blame = await this.blameRequestDbService.findById(
|
||||
String(claimCase.blameRequestId),
|
||||
);
|
||||
if (!blame) {
|
||||
return defaultLocation;
|
||||
}
|
||||
|
||||
return this.fanavaranLocationService.resolveBusinessLocation({
|
||||
clientKey,
|
||||
staffCandidateIds: [
|
||||
(blame as any)?.initiatedByFieldExpertId,
|
||||
(blame as any)?.expert?.assignedExpertId,
|
||||
(blame as any)?.expert?.decision?.decidedByExpertId,
|
||||
(claimCase as any)?.initiatedByFieldExpertId,
|
||||
this.fanavaranDamageReplyActorId(claimCase),
|
||||
(claimCase as any)?.workflow?.assignedForReviewBy?.actorId,
|
||||
(blame as any)?.assignedFileReviewerId,
|
||||
],
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
`[Fanavaran Location] Failed to resolve for claimCaseId=${claimCaseId}; using tenant default`,
|
||||
error,
|
||||
);
|
||||
return defaultLocation;
|
||||
const claimCase = await this.claimCaseDbService.findById(claimCaseId);
|
||||
if (!claimCase) {
|
||||
throw new NotFoundException('Claim case not found');
|
||||
}
|
||||
|
||||
const blame = claimCase.blameRequestId
|
||||
? await this.blameRequestDbService.findById(String(claimCase.blameRequestId))
|
||||
: null;
|
||||
|
||||
return this.fanavaranLocationService.resolveBusinessLocation({
|
||||
clientKey,
|
||||
requireStaffLocation: true,
|
||||
staffCandidateIds: [
|
||||
claimCase.initiatedByFieldExpertId,
|
||||
blame?.initiatedByFieldExpertId,
|
||||
this.fanavaranDamageReplyActorId(claimCase),
|
||||
claimCase.workflow?.assignedForReviewBy?.actorId,
|
||||
blame?.assignedFileReviewerId,
|
||||
blame?.expert?.assignedExpertId,
|
||||
blame?.expert?.decision?.decidedByExpertId,
|
||||
].map((id) => (id == null ? undefined : String(id))),
|
||||
});
|
||||
}
|
||||
|
||||
private fanavaranPayloadDefaultsWithoutExpertIds(
|
||||
@@ -3839,17 +3828,6 @@ export class ClaimRequestManagementService {
|
||||
InsuranceLineId: insuranceLineId,
|
||||
};
|
||||
|
||||
if (auditSession) {
|
||||
await this.fanavaranAuditService.recordStep({
|
||||
session: auditSession,
|
||||
step: FanavaranAuditStep.POLICY_INQUIRY,
|
||||
status: FanavaranAuditStatus.STARTED,
|
||||
requestUrl: policyInquiryUrl,
|
||||
requestMethod: 'GET',
|
||||
requestMeta,
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
this.fanavaranAuthService.assertNotInBackoff(clientKey);
|
||||
const headers = await this.getFanavaranAuthHeaders(
|
||||
@@ -3861,6 +3839,19 @@ export class ClaimRequestManagementService {
|
||||
...headers,
|
||||
'Content-Type': 'application/json',
|
||||
};
|
||||
requestMeta.location = headers.Location;
|
||||
|
||||
if (auditSession) {
|
||||
await this.fanavaranAuditService.recordStep({
|
||||
session: auditSession,
|
||||
step: FanavaranAuditStep.POLICY_INQUIRY,
|
||||
status: FanavaranAuditStatus.STARTED,
|
||||
requestUrl: policyInquiryUrl,
|
||||
requestMethod: 'GET',
|
||||
requestHeaders,
|
||||
requestMeta,
|
||||
});
|
||||
}
|
||||
|
||||
this.logger.log(
|
||||
`${logPrefix} Calling policy inquiry API for nationalCode: ${nationalCodeOfInsurer}`,
|
||||
@@ -4220,10 +4211,14 @@ export class ClaimRequestManagementService {
|
||||
});
|
||||
|
||||
try {
|
||||
const created = await this.fanavaranLookupService.createOtherPerson(
|
||||
input.clientKey,
|
||||
const response = await this.postFanavaranJson(
|
||||
url,
|
||||
payload,
|
||||
input.clientKey,
|
||||
auditSession,
|
||||
input.claimCaseId,
|
||||
);
|
||||
const created = response.data;
|
||||
const personId = pickFanavaranRecordId(created);
|
||||
await this.fanavaranAuditService.recordStep({
|
||||
session: auditSession,
|
||||
|
||||
Reference in New Issue
Block a user