forked from Yara724/api
locations dynamically in fanavaran
This commit is contained in:
@@ -102,6 +102,7 @@ import { ImageRequiredModel } from "./entites/schema/image-required.schema";
|
||||
import { DamageExpertDbService } from "src/users/entities/db-service/damage-expert.db.service";
|
||||
import { FileMakerDbService } from "src/users/entities/db-service/file-maker.db.service";
|
||||
import { FieldExpertDbService } from "src/users/entities/db-service/field-expert.db.service";
|
||||
import { FanavaranLocationService } from "src/fanavaran/fanavaran-location.service";
|
||||
import { ExpertFileActivityDbService } from "src/users/entities/db-service/expert-file-activity.db.service";
|
||||
import { SandHubService } from "src/sand-hub/sand-hub.service";
|
||||
import {
|
||||
@@ -393,6 +394,7 @@ export class ClaimRequestManagementService {
|
||||
private readonly fileMakerDbService: FileMakerDbService,
|
||||
private readonly fieldExpertDbService: FieldExpertDbService,
|
||||
private readonly plateNormalizer: PlateNormalizerService,
|
||||
private readonly fanavaranLocationService: FanavaranLocationService,
|
||||
) {}
|
||||
|
||||
private requiredDocumentKeysV2(isCarBody: boolean): string[] {
|
||||
@@ -4365,12 +4367,63 @@ export class ClaimRequestManagementService {
|
||||
private async getFanavaranAuthHeaders(
|
||||
clientKey: FanavaranClientKey,
|
||||
auditSession?: FanavaranAuditSession,
|
||||
claimCaseId?: string,
|
||||
) {
|
||||
const caseId = claimCaseId ?? auditSession?.claimCaseId;
|
||||
const locationOverride = caseId
|
||||
? await this.resolveFanavaranLocationForClaim(caseId, clientKey)
|
||||
: undefined;
|
||||
return this.fanavaranAuthService.getRequestHeaders(clientKey, {
|
||||
auditSession,
|
||||
locationOverride,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Parsian + V4/V5 FileMaker flows: Location from file-maker.locations[].id,
|
||||
* else file-reviewer.locations[].id, else tenant auth.location.
|
||||
*/
|
||||
private async resolveFanavaranLocationForClaim(
|
||||
claimCaseId: string,
|
||||
clientKey: FanavaranClientKey,
|
||||
): Promise<string> {
|
||||
const defaultLocation = getFanavaranClientProfile(clientKey).auth.location;
|
||||
if (clientKey !== "parsian") {
|
||||
return defaultLocation;
|
||||
}
|
||||
|
||||
try {
|
||||
const claimCase = await this.claimCaseDbService.findById(claimCaseId);
|
||||
if (!claimCase?.blameRequestId) {
|
||||
return defaultLocation;
|
||||
}
|
||||
|
||||
const blame = await this.blameRequestDbService.findById(
|
||||
String(claimCase.blameRequestId),
|
||||
);
|
||||
if (!(blame as any)?.isMadeByFileMaker) {
|
||||
return defaultLocation;
|
||||
}
|
||||
|
||||
return this.fanavaranLocationService.resolveBusinessLocation({
|
||||
clientKey,
|
||||
isMadeByFileMaker: true,
|
||||
fileMakerId: (blame as any)?.initiatedByFieldExpertId
|
||||
? String((blame as any).initiatedByFieldExpertId)
|
||||
: null,
|
||||
fileReviewerId: (blame as any)?.assignedFileReviewerId
|
||||
? String((blame as any).assignedFileReviewerId)
|
||||
: null,
|
||||
});
|
||||
} catch (error) {
|
||||
this.logger.warn(
|
||||
`[Fanavaran Location] Failed to resolve for claimCaseId=${claimCaseId}; using tenant default`,
|
||||
error,
|
||||
);
|
||||
return defaultLocation;
|
||||
}
|
||||
}
|
||||
|
||||
private async getPolicyIdFromNationalCode(
|
||||
nationalCodeOfInsurer: string,
|
||||
config: {
|
||||
@@ -4417,6 +4470,7 @@ export class ClaimRequestManagementService {
|
||||
const headers = await this.getFanavaranAuthHeaders(
|
||||
clientKey,
|
||||
auditSession,
|
||||
options?.claimCaseId,
|
||||
);
|
||||
const requestHeaders = {
|
||||
...headers,
|
||||
@@ -5220,6 +5274,8 @@ export class ClaimRequestManagementService {
|
||||
content,
|
||||
[{ path: candidate.path, fileName: candidate.fileName }],
|
||||
clientKey,
|
||||
undefined,
|
||||
claimCaseId,
|
||||
);
|
||||
this.logger.log(
|
||||
`${logPrefix} [${i + 1}/${pending.length}] SUCCESS: status=${response.status} body=${JSON.stringify(response.data)}`,
|
||||
@@ -6276,9 +6332,14 @@ export class ClaimRequestManagementService {
|
||||
payload: Record<string, unknown>,
|
||||
clientKey: FanavaranClientKey,
|
||||
auditSession?: FanavaranAuditSession,
|
||||
claimCaseId?: string,
|
||||
) {
|
||||
this.fanavaranAuthService.assertNotInBackoff(clientKey);
|
||||
const headers = await this.getFanavaranAuthHeaders(clientKey, auditSession);
|
||||
const headers = await this.getFanavaranAuthHeaders(
|
||||
clientKey,
|
||||
auditSession,
|
||||
claimCaseId,
|
||||
);
|
||||
|
||||
try {
|
||||
const response = await firstValueFrom(
|
||||
@@ -6303,9 +6364,14 @@ export class ClaimRequestManagementService {
|
||||
files: Array<{ path: string; fileName: string }>,
|
||||
clientKey: FanavaranClientKey,
|
||||
auditSession?: FanavaranAuditSession,
|
||||
claimCaseId?: string,
|
||||
) {
|
||||
this.fanavaranAuthService.assertNotInBackoff(clientKey);
|
||||
const headers = await this.getFanavaranAuthHeaders(clientKey, auditSession);
|
||||
const headers = await this.getFanavaranAuthHeaders(
|
||||
clientKey,
|
||||
auditSession,
|
||||
claimCaseId,
|
||||
);
|
||||
const form = new FormData();
|
||||
|
||||
form.append("Param", JSON.stringify(content), {
|
||||
@@ -7242,6 +7308,7 @@ export class ClaimRequestManagementService {
|
||||
const headers = await this.getFanavaranAuthHeaders(
|
||||
clientKey,
|
||||
auditSession,
|
||||
claimCaseId,
|
||||
);
|
||||
|
||||
const requestHeaders = {
|
||||
|
||||
Reference in New Issue
Block a user