forked from Yara724/api
expert codes
This commit is contained in:
@@ -32,8 +32,6 @@ import { BranchDbService } from "src/client/entities/db-service/branch.db.servic
|
|||||||
import { InquiryParticipantRole } from "src/common/dto/inquiry-participants.dto";
|
import { InquiryParticipantRole } from "src/common/dto/inquiry-participants.dto";
|
||||||
import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
import { ListQueryV2Dto } from "src/common/dto/list-query-v2.dto";
|
||||||
import {
|
import {
|
||||||
assertFileMakerCanCreateBlameType,
|
|
||||||
assertFileReviewerCanReviewBlameType,
|
|
||||||
resolveFileMakerStageOneExpertId,
|
resolveFileMakerStageOneExpertId,
|
||||||
resolveFileReviewerExpertiseExpertId,
|
resolveFileReviewerExpertiseExpertId,
|
||||||
type StaffFanavaranExpertiseCodes,
|
type StaffFanavaranExpertiseCodes,
|
||||||
@@ -3394,6 +3392,35 @@ export class ClaimRequestManagementService {
|
|||||||
return rest;
|
return rest;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private staffFanavaranCodesFromDoc(
|
||||||
|
doc: unknown,
|
||||||
|
): (StaffFanavaranStageOneCodes & StaffFanavaranExpertiseCodes) | null {
|
||||||
|
if (!doc || typeof doc !== "object") return null;
|
||||||
|
const plain =
|
||||||
|
typeof (doc as { toObject?: () => Record<string, unknown> }).toObject ===
|
||||||
|
"function"
|
||||||
|
? (doc as { toObject: () => Record<string, unknown> }).toObject()
|
||||||
|
: (doc as Record<string, unknown>);
|
||||||
|
return {
|
||||||
|
ThirdPartyClaimExpertId:
|
||||||
|
plain.ThirdPartyClaimExpertId != null
|
||||||
|
? String(plain.ThirdPartyClaimExpertId)
|
||||||
|
: undefined,
|
||||||
|
CarBodyClaimExpertId:
|
||||||
|
plain.CarBodyClaimExpertId != null
|
||||||
|
? String(plain.CarBodyClaimExpertId)
|
||||||
|
: undefined,
|
||||||
|
ThirdPartyExpertiseClaim:
|
||||||
|
plain.ThirdPartyExpertiseClaim != null
|
||||||
|
? String(plain.ThirdPartyExpertiseClaim)
|
||||||
|
: undefined,
|
||||||
|
CarBodyExpertiseClaim:
|
||||||
|
plain.CarBodyExpertiseClaim != null
|
||||||
|
? String(plain.CarBodyExpertiseClaim)
|
||||||
|
: undefined,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
private async findStaffDocumentById(
|
private async findStaffDocumentById(
|
||||||
staffId: string,
|
staffId: string,
|
||||||
): Promise<
|
): Promise<
|
||||||
@@ -3401,22 +3428,130 @@ export class ClaimRequestManagementService {
|
|||||||
| null
|
| null
|
||||||
> {
|
> {
|
||||||
const loaders = [
|
const loaders = [
|
||||||
() => this.fileMakerDbService.findById(staffId),
|
|
||||||
() => this.fileReviewerDbService.findById(staffId),
|
|
||||||
() => this.fieldExpertDbService.findById(staffId),
|
|
||||||
() => this.expertDbService.findById(staffId),
|
() => this.expertDbService.findById(staffId),
|
||||||
() => this.damageExpertDbService.findById(staffId),
|
() => this.damageExpertDbService.findById(staffId),
|
||||||
|
() => this.fieldExpertDbService.findById(staffId),
|
||||||
|
() => this.fileMakerDbService.findById(staffId),
|
||||||
|
() => this.fileReviewerDbService.findById(staffId),
|
||||||
];
|
];
|
||||||
for (const load of loaders) {
|
for (const load of loaders) {
|
||||||
const doc = await load();
|
try {
|
||||||
if (doc) return doc as StaffFanavaranStageOneCodes & StaffFanavaranExpertiseCodes;
|
const doc = await load();
|
||||||
|
const codes = this.staffFanavaranCodesFromDoc(doc);
|
||||||
|
if (codes) return codes;
|
||||||
|
} catch {
|
||||||
|
// invalid ObjectId / cast errors — try next collection
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async tryResolveFanavaranBaseClaimExpertId(
|
||||||
|
blame: {
|
||||||
|
isMadeByFileMaker?: boolean;
|
||||||
|
type?: BlameRequestType;
|
||||||
|
initiatedByFieldExpertId?: unknown;
|
||||||
|
assignedFileReviewerId?: unknown;
|
||||||
|
expert?: {
|
||||||
|
assignedExpertId?: unknown;
|
||||||
|
decision?: { decidedByExpertId?: unknown };
|
||||||
|
};
|
||||||
|
},
|
||||||
|
claimCase?: { initiatedByFieldExpertId?: unknown } | null,
|
||||||
|
): Promise<{
|
||||||
|
claimExpertId: number | null;
|
||||||
|
code: string | null;
|
||||||
|
message: string | null;
|
||||||
|
candidatesTried: string[];
|
||||||
|
}> {
|
||||||
|
const fieldName =
|
||||||
|
blame?.type === BlameRequestType.CAR_BODY
|
||||||
|
? "CarBodyClaimExpertId"
|
||||||
|
: "ThirdPartyClaimExpertId";
|
||||||
|
|
||||||
|
if (blame?.type == null) {
|
||||||
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
|
code: "FANAVARAN_CLAIM_EXPERT_ID_MISSING",
|
||||||
|
message:
|
||||||
|
"ClaimExpertId unresolved: blame.type is missing, so the product line expert code cannot be chosen.",
|
||||||
|
candidatesTried: [],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (blame.isMadeByFileMaker && blame.initiatedByFieldExpertId) {
|
||||||
|
const fileMakerId = String(blame.initiatedByFieldExpertId);
|
||||||
|
const fileMaker = await this.fileMakerDbService.findById(fileMakerId);
|
||||||
|
if (!fileMaker) {
|
||||||
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
|
code: "FILE_MAKER_FANAVARAN_EXPERT_CODE_MISSING",
|
||||||
|
message: `ClaimExpertId unresolved: FileMaker ${fileMakerId} was not found.`,
|
||||||
|
candidatesTried: [fileMakerId],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
const id = resolveFileMakerStageOneExpertId(fileMaker, blame.type);
|
||||||
|
if (id == null) {
|
||||||
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
|
code: "FILE_MAKER_FANAVARAN_EXPERT_CODE_MISSING",
|
||||||
|
message: `ClaimExpertId unresolved: FileMaker ${fileMakerId} has empty ${fieldName}.`,
|
||||||
|
candidatesTried: [fileMakerId],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
claimExpertId: id,
|
||||||
|
code: null,
|
||||||
|
message: null,
|
||||||
|
candidatesTried: [fileMakerId],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
const candidateIds = [
|
||||||
|
blame.initiatedByFieldExpertId,
|
||||||
|
blame.expert?.assignedExpertId,
|
||||||
|
blame.expert?.decision?.decidedByExpertId,
|
||||||
|
claimCase?.initiatedByFieldExpertId,
|
||||||
|
]
|
||||||
|
.filter((value) => value != null && String(value).trim() !== "")
|
||||||
|
.map((value) => String(value));
|
||||||
|
|
||||||
|
const missingOnStaff: string[] = [];
|
||||||
|
for (const staffId of candidateIds) {
|
||||||
|
const staff = await this.findStaffDocumentById(staffId);
|
||||||
|
if (!staff) {
|
||||||
|
missingOnStaff.push(`${staffId} (staff not found in expert/damage/field/fileMaker/fileReviewer)`);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const rawValue = (staff as Record<string, unknown>)[fieldName];
|
||||||
|
const id = resolveFileMakerStageOneExpertId(staff, blame.type);
|
||||||
|
if (id != null) {
|
||||||
|
return {
|
||||||
|
claimExpertId: id,
|
||||||
|
code: null,
|
||||||
|
message: null,
|
||||||
|
candidatesTried: candidateIds,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
missingOnStaff.push(
|
||||||
|
`${staffId} (${fieldName}=${rawValue == null || rawValue === "" ? "empty" : JSON.stringify(rawValue)})`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
|
code: "FANAVARAN_CLAIM_EXPERT_ID_MISSING",
|
||||||
|
message:
|
||||||
|
candidateIds.length === 0
|
||||||
|
? `ClaimExpertId unresolved: this claim/blame has no assigned staff id (checked initiatedByFieldExpertId, expert.assignedExpertId, expert.decision.decidedByExpertId). Codes like ThirdPartyClaimExpertId=5507 on some other staff profile are ignored until that staff is assigned to this file.`
|
||||||
|
: `ClaimExpertId unresolved: checked assigned staff [${missingOnStaff.join("; ")}]. Your ${fieldName} must be on THAT assigned staff document, not a different user.`,
|
||||||
|
candidatesTried: candidateIds,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* GEN.03 ClaimExpertId from the staff assigned to this file (never tenant defaults).
|
* GEN.03 ClaimExpertId from the staff assigned to this file (never tenant defaults).
|
||||||
* V4/V5 FileMaker → FileMaker codes; otherwise field/blame/claim expert assignment.
|
* Preview may pass `{ required: false }` to keep building the payload with null.
|
||||||
*/
|
*/
|
||||||
private async resolveFanavaranBaseClaimExpertId(
|
private async resolveFanavaranBaseClaimExpertId(
|
||||||
blame: {
|
blame: {
|
||||||
@@ -3430,109 +3565,86 @@ export class ClaimRequestManagementService {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
claimCase?: { initiatedByFieldExpertId?: unknown } | null,
|
claimCase?: { initiatedByFieldExpertId?: unknown } | null,
|
||||||
): Promise<number> {
|
options?: { required?: boolean },
|
||||||
if (blame?.type == null) {
|
): Promise<number | null> {
|
||||||
throw new BadRequestException({
|
const resolved = await this.tryResolveFanavaranBaseClaimExpertId(
|
||||||
code: "FANAVARAN_CLAIM_EXPERT_ID_MISSING",
|
blame,
|
||||||
message:
|
claimCase,
|
||||||
"Cannot resolve Fanavaran ClaimExpertId: blame product type is missing.",
|
);
|
||||||
});
|
if (resolved.claimExpertId != null) return resolved.claimExpertId;
|
||||||
}
|
if (options?.required === false) return null;
|
||||||
|
|
||||||
if (blame.isMadeByFileMaker && blame.initiatedByFieldExpertId) {
|
|
||||||
const fileMaker = await this.fileMakerDbService.findById(
|
|
||||||
String(blame.initiatedByFieldExpertId),
|
|
||||||
);
|
|
||||||
if (!fileMaker) {
|
|
||||||
throw new BadRequestException({
|
|
||||||
code: "FILE_MAKER_FANAVARAN_EXPERT_CODE_MISSING",
|
|
||||||
message:
|
|
||||||
"This FileMaker file cannot be submitted to Fanavaran: FileMaker profile was not found.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
assertFileMakerCanCreateBlameType(fileMaker, blame.type);
|
|
||||||
const id = resolveFileMakerStageOneExpertId(fileMaker, blame.type);
|
|
||||||
if (id == null) {
|
|
||||||
throw new BadRequestException({
|
|
||||||
code: "FILE_MAKER_FANAVARAN_EXPERT_CODE_MISSING",
|
|
||||||
message:
|
|
||||||
"This FileMaker file cannot be submitted to Fanavaran: stage-1 claim expert id is missing for this product line.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
const candidateIds = [
|
|
||||||
blame.initiatedByFieldExpertId,
|
|
||||||
blame.expert?.assignedExpertId,
|
|
||||||
blame.expert?.decision?.decidedByExpertId,
|
|
||||||
claimCase?.initiatedByFieldExpertId,
|
|
||||||
]
|
|
||||||
.filter((value) => value != null && String(value).trim() !== "")
|
|
||||||
.map((value) => String(value));
|
|
||||||
|
|
||||||
for (const staffId of candidateIds) {
|
|
||||||
const staff = await this.findStaffDocumentById(staffId);
|
|
||||||
if (!staff) continue;
|
|
||||||
const id = resolveFileMakerStageOneExpertId(staff, blame.type);
|
|
||||||
if (id != null) return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new BadRequestException({
|
throw new BadRequestException({
|
||||||
code: "FANAVARAN_CLAIM_EXPERT_ID_MISSING",
|
code: resolved.code ?? "FANAVARAN_CLAIM_EXPERT_ID_MISSING",
|
||||||
message:
|
message:
|
||||||
"Fanavaran ClaimExpertId is missing on the assigned expert profile for this product line. Set ThirdPartyClaimExpertId or CarBodyClaimExpertId on the assigned staff.",
|
resolved.message ??
|
||||||
|
"ClaimExpertId unresolved on the assigned expert profile.",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
private async tryResolveFanavaranExpertiseClaimExpertId(
|
||||||
* GEN.08 / GEN.06 ClaimExpertId from the assessor assigned to this file (never tenant defaults).
|
|
||||||
* V4/V5 FileMaker → FileReviewer; otherwise the damage-expert (or other staff) who priced the claim.
|
|
||||||
*/
|
|
||||||
private async resolveFanavaranExpertiseClaimExpertId(
|
|
||||||
blame: {
|
blame: {
|
||||||
isMadeByFileMaker?: boolean;
|
isMadeByFileMaker?: boolean;
|
||||||
type?: BlameRequestType;
|
type?: BlameRequestType;
|
||||||
assignedFileReviewerId?: unknown;
|
assignedFileReviewerId?: unknown;
|
||||||
},
|
},
|
||||||
claimCase: { evaluation?: Record<string, unknown> } | null | undefined,
|
claimCase: { evaluation?: Record<string, unknown> } | null | undefined,
|
||||||
): Promise<number> {
|
): Promise<{
|
||||||
|
claimExpertId: number | null;
|
||||||
|
code: string | null;
|
||||||
|
message: string | null;
|
||||||
|
candidatesTried: string[];
|
||||||
|
}> {
|
||||||
|
const fieldName =
|
||||||
|
blame?.type === BlameRequestType.CAR_BODY
|
||||||
|
? "CarBodyExpertiseClaim"
|
||||||
|
: "ThirdPartyExpertiseClaim";
|
||||||
|
|
||||||
if (blame?.type == null) {
|
if (blame?.type == null) {
|
||||||
throw new BadRequestException({
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
||||||
message:
|
message:
|
||||||
"Cannot resolve Fanavaran expertise ClaimExpertId: blame product type is missing.",
|
"Expertise ClaimExpertId unresolved: blame.type is missing.",
|
||||||
});
|
candidatesTried: [],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (blame.isMadeByFileMaker) {
|
if (blame.isMadeByFileMaker) {
|
||||||
if (!blame.assignedFileReviewerId) {
|
if (!blame.assignedFileReviewerId) {
|
||||||
throw new BadRequestException({
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING",
|
code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING",
|
||||||
message:
|
message:
|
||||||
"Fanavaran expertise cannot be submitted: assign a FileReviewer with an expertise claim expert id for this product line.",
|
"Expertise ClaimExpertId unresolved: no assignedFileReviewerId on this FileMaker file.",
|
||||||
});
|
candidatesTried: [],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
const fileReviewer = await this.fileReviewerDbService.findById(
|
const fileReviewerId = String(blame.assignedFileReviewerId);
|
||||||
String(blame.assignedFileReviewerId),
|
const fileReviewer =
|
||||||
);
|
await this.fileReviewerDbService.findById(fileReviewerId);
|
||||||
if (!fileReviewer) {
|
if (!fileReviewer) {
|
||||||
throw new BadRequestException({
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING",
|
code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING",
|
||||||
message:
|
message: `Expertise ClaimExpertId unresolved: FileReviewer ${fileReviewerId} was not found.`,
|
||||||
"Fanavaran expertise cannot be submitted: FileReviewer profile was not found.",
|
candidatesTried: [fileReviewerId],
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
assertFileReviewerCanReviewBlameType(fileReviewer, blame.type);
|
|
||||||
const id = resolveFileReviewerExpertiseExpertId(fileReviewer, blame.type);
|
const id = resolveFileReviewerExpertiseExpertId(fileReviewer, blame.type);
|
||||||
if (id == null) {
|
if (id == null) {
|
||||||
throw new BadRequestException({
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING",
|
code: "FILE_REVIEWER_FANAVARAN_EXPERT_CODE_MISSING",
|
||||||
message:
|
message: `Expertise ClaimExpertId unresolved: FileReviewer ${fileReviewerId} has empty ${fieldName}.`,
|
||||||
"Fanavaran expertise cannot be submitted: assign a FileReviewer with an expertise claim expert id for this product line.",
|
candidatesTried: [fileReviewerId],
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
return id;
|
return {
|
||||||
|
claimExpertId: id,
|
||||||
|
code: null,
|
||||||
|
message: null,
|
||||||
|
candidatesTried: [fileReviewerId],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const evaluation = claimCase?.evaluation as
|
const evaluation = claimCase?.evaluation as
|
||||||
@@ -3550,25 +3662,67 @@ export class ClaimRequestManagementService {
|
|||||||
evaluation?.damageExpertReplyFinal?.actorDetail?.actorId ??
|
evaluation?.damageExpertReplyFinal?.actorDetail?.actorId ??
|
||||||
evaluation?.damageExpertReply?.actorDetail?.actorId;
|
evaluation?.damageExpertReply?.actorDetail?.actorId;
|
||||||
if (actorId == null || String(actorId).trim() === "") {
|
if (actorId == null || String(actorId).trim() === "") {
|
||||||
throw new BadRequestException({
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
||||||
message:
|
message:
|
||||||
"Fanavaran expertise ClaimExpertId cannot be resolved: no damage-expert reply actor is assigned on this claim.",
|
"Expertise ClaimExpertId unresolved: no damage-expert reply actorDetail.actorId on this claim.",
|
||||||
});
|
candidatesTried: [],
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const staff = await this.findStaffDocumentById(String(actorId));
|
const staffId = String(actorId);
|
||||||
const id = staff
|
const staff = await this.findStaffDocumentById(staffId);
|
||||||
? resolveFileReviewerExpertiseExpertId(staff, blame.type)
|
if (!staff) {
|
||||||
: null;
|
return {
|
||||||
if (id == null) {
|
claimExpertId: null,
|
||||||
throw new BadRequestException({
|
|
||||||
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
||||||
message:
|
message: `Expertise ClaimExpertId unresolved: staff ${staffId} was not found.`,
|
||||||
"Fanavaran ClaimExpertId is missing on the assigned assessor profile for this product line. Set ThirdPartyExpertiseClaim or CarBodyExpertiseClaim on the assigned staff.",
|
candidatesTried: [staffId],
|
||||||
});
|
};
|
||||||
}
|
}
|
||||||
return id;
|
const id = resolveFileReviewerExpertiseExpertId(staff, blame.type);
|
||||||
|
if (id == null) {
|
||||||
|
return {
|
||||||
|
claimExpertId: null,
|
||||||
|
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
||||||
|
message: `Expertise ClaimExpertId unresolved: staff ${staffId} has empty ${fieldName}.`,
|
||||||
|
candidatesTried: [staffId],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
claimExpertId: id,
|
||||||
|
code: null,
|
||||||
|
message: null,
|
||||||
|
candidatesTried: [staffId],
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* GEN.08 / GEN.06 ClaimExpertId from the assessor assigned to this file (never tenant defaults).
|
||||||
|
* Preview may pass `{ required: false }` to keep building the payload with null.
|
||||||
|
*/
|
||||||
|
private async resolveFanavaranExpertiseClaimExpertId(
|
||||||
|
blame: {
|
||||||
|
isMadeByFileMaker?: boolean;
|
||||||
|
type?: BlameRequestType;
|
||||||
|
assignedFileReviewerId?: unknown;
|
||||||
|
},
|
||||||
|
claimCase: { evaluation?: Record<string, unknown> } | null | undefined,
|
||||||
|
options?: { required?: boolean },
|
||||||
|
): Promise<number | null> {
|
||||||
|
const resolved = await this.tryResolveFanavaranExpertiseClaimExpertId(
|
||||||
|
blame,
|
||||||
|
claimCase,
|
||||||
|
);
|
||||||
|
if (resolved.claimExpertId != null) return resolved.claimExpertId;
|
||||||
|
if (options?.required === false) return null;
|
||||||
|
throw new BadRequestException({
|
||||||
|
code: resolved.code ?? "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
||||||
|
message:
|
||||||
|
resolved.message ??
|
||||||
|
"Expertise ClaimExpertId unresolved on the assigned assessor profile.",
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @deprecated Use resolveFanavaranBaseClaimExpertId / resolveFanavaranExpertiseClaimExpertId */
|
/** @deprecated Use resolveFanavaranBaseClaimExpertId / resolveFanavaranExpertiseClaimExpertId */
|
||||||
@@ -4190,6 +4344,12 @@ export class ClaimRequestManagementService {
|
|||||||
resolvePolicy?: boolean;
|
resolvePolicy?: boolean;
|
||||||
/** When true (submit), missing PolicyId throws. Preview keeps payload even if inquiry fails. */
|
/** When true (submit), missing PolicyId throws. Preview keeps payload even if inquiry fails. */
|
||||||
requirePolicyId?: boolean;
|
requirePolicyId?: boolean;
|
||||||
|
/**
|
||||||
|
* When false (HTTP preview), missing staff ClaimExpertId stays null and is
|
||||||
|
* reported in previewWarnings instead of throwing.
|
||||||
|
* Submit keeps the default (required).
|
||||||
|
*/
|
||||||
|
requireClaimExpertId?: boolean;
|
||||||
auditSession?: FanavaranAuditSession;
|
auditSession?: FanavaranAuditSession;
|
||||||
/** Persist built payload onto fanavaranSync.baseClaim.lastPayload (default true). */
|
/** Persist built payload onto fanavaranSync.baseClaim.lastPayload (default true). */
|
||||||
persistPayload?: boolean;
|
persistPayload?: boolean;
|
||||||
@@ -4209,7 +4369,14 @@ export class ClaimRequestManagementService {
|
|||||||
const forceRefreshPolicy = options?.forceRefreshPolicy === true;
|
const forceRefreshPolicy = options?.forceRefreshPolicy === true;
|
||||||
const forceRefreshUsedId = options?.forceRefreshUsedId === true;
|
const forceRefreshUsedId = options?.forceRefreshUsedId === true;
|
||||||
const requirePolicyId = options?.requirePolicyId === true;
|
const requirePolicyId = options?.requirePolicyId === true;
|
||||||
|
const requireClaimExpertId = options?.requireClaimExpertId !== false;
|
||||||
const persistPayload = options?.persistPayload !== false;
|
const persistPayload = options?.persistPayload !== false;
|
||||||
|
const previewWarnings: Array<{
|
||||||
|
code: string;
|
||||||
|
message: string;
|
||||||
|
field: string;
|
||||||
|
candidatesTried?: string[];
|
||||||
|
}> = [];
|
||||||
const auditSession =
|
const auditSession =
|
||||||
options?.auditSession ??
|
options?.auditSession ??
|
||||||
({
|
({
|
||||||
@@ -4583,10 +4750,34 @@ export class ClaimRequestManagementService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
payload.ClaimExpertId = await this.resolveFanavaranBaseClaimExpertId(
|
const claimExpertResolution =
|
||||||
blameCase,
|
await this.tryResolveFanavaranBaseClaimExpertId(blameCase, claimCase);
|
||||||
claimCase,
|
payload.ClaimExpertId = claimExpertResolution.claimExpertId;
|
||||||
);
|
(debug as any).steps.claimExpertIdResolved =
|
||||||
|
claimExpertResolution.claimExpertId != null;
|
||||||
|
(debug as any).values.claimExpertId =
|
||||||
|
claimExpertResolution.claimExpertId;
|
||||||
|
(debug as any).values.claimExpertIdCandidatesTried =
|
||||||
|
claimExpertResolution.candidatesTried;
|
||||||
|
if (claimExpertResolution.claimExpertId == null) {
|
||||||
|
const warning = {
|
||||||
|
code:
|
||||||
|
claimExpertResolution.code ?? "FANAVARAN_CLAIM_EXPERT_ID_MISSING",
|
||||||
|
message:
|
||||||
|
claimExpertResolution.message ??
|
||||||
|
"ClaimExpertId unresolved on the assigned expert profile.",
|
||||||
|
field: "ClaimExpertId",
|
||||||
|
candidatesTried: claimExpertResolution.candidatesTried,
|
||||||
|
};
|
||||||
|
previewWarnings.push(warning);
|
||||||
|
(debug as any).values.claimExpertIdWarning = warning.message;
|
||||||
|
if (requireClaimExpertId) {
|
||||||
|
throw new BadRequestException({
|
||||||
|
code: warning.code,
|
||||||
|
message: warning.message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (persistPayload) {
|
if (persistPayload) {
|
||||||
await this.claimCaseDbService.findByIdAndUpdate(claimCaseId, {
|
await this.claimCaseDbService.findByIdAndUpdate(claimCaseId, {
|
||||||
@@ -4617,6 +4808,14 @@ export class ClaimRequestManagementService {
|
|||||||
clientKey,
|
clientKey,
|
||||||
payload,
|
payload,
|
||||||
debug,
|
debug,
|
||||||
|
previewWarnings,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previewWarnings.length > 0) {
|
||||||
|
return {
|
||||||
|
payload,
|
||||||
|
previewWarnings,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5557,6 +5756,8 @@ export class ClaimRequestManagementService {
|
|||||||
private async buildFanavaranExpertisePayload(input: {
|
private async buildFanavaranExpertisePayload(input: {
|
||||||
claimCase: any;
|
claimCase: any;
|
||||||
clientKey: FanavaranClientKey;
|
clientKey: FanavaranClientKey;
|
||||||
|
/** Preview keeps null ClaimExpertId; submit requires it. Default true. */
|
||||||
|
requireClaimExpertId?: boolean;
|
||||||
}): Promise<{
|
}): Promise<{
|
||||||
payload: Record<string, unknown>;
|
payload: Record<string, unknown>;
|
||||||
warnings: string[];
|
warnings: string[];
|
||||||
@@ -5564,6 +5765,7 @@ export class ClaimRequestManagementService {
|
|||||||
}> {
|
}> {
|
||||||
const profile = getFanavaranClientProfile(input.clientKey);
|
const profile = getFanavaranClientProfile(input.clientKey);
|
||||||
const active = getActiveV2ExpertReply(input.claimCase as any);
|
const active = getActiveV2ExpertReply(input.claimCase as any);
|
||||||
|
const requireClaimExpertId = input.requireClaimExpertId !== false;
|
||||||
|
|
||||||
const blameForExpertIds = input.claimCase?.blameRequestId
|
const blameForExpertIds = input.claimCase?.blameRequestId
|
||||||
? await this.blameRequestDbService.findById(
|
? await this.blameRequestDbService.findById(
|
||||||
@@ -5572,22 +5774,42 @@ export class ClaimRequestManagementService {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
// GEN.08 / GEN.06 ClaimExpertId always from assigned assessor staff profile.
|
// GEN.08 / GEN.06 ClaimExpertId always from assigned assessor staff profile.
|
||||||
if (!blameForExpertIds) {
|
|
||||||
throw new BadRequestException({
|
|
||||||
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
|
||||||
message:
|
|
||||||
"Fanavaran expertise cannot be submitted: linked blame case was not found.",
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const claimExpertId = await this.resolveFanavaranExpertiseClaimExpertId(
|
|
||||||
blameForExpertIds as {
|
|
||||||
isMadeByFileMaker?: boolean;
|
|
||||||
type?: BlameRequestType;
|
|
||||||
assignedFileReviewerId?: unknown;
|
|
||||||
},
|
|
||||||
input.claimCase,
|
|
||||||
);
|
|
||||||
const warnings: string[] = [];
|
const warnings: string[] = [];
|
||||||
|
let claimExpertId: number | null = null;
|
||||||
|
if (!blameForExpertIds) {
|
||||||
|
const message =
|
||||||
|
"Expertise ClaimExpertId unresolved: linked blame case was not found.";
|
||||||
|
if (requireClaimExpertId) {
|
||||||
|
throw new BadRequestException({
|
||||||
|
code: "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
warnings.push(message);
|
||||||
|
} else {
|
||||||
|
const resolved = await this.tryResolveFanavaranExpertiseClaimExpertId(
|
||||||
|
blameForExpertIds as {
|
||||||
|
isMadeByFileMaker?: boolean;
|
||||||
|
type?: BlameRequestType;
|
||||||
|
assignedFileReviewerId?: unknown;
|
||||||
|
},
|
||||||
|
input.claimCase,
|
||||||
|
);
|
||||||
|
claimExpertId = resolved.claimExpertId;
|
||||||
|
if (resolved.claimExpertId == null) {
|
||||||
|
const message =
|
||||||
|
resolved.message ??
|
||||||
|
"Expertise ClaimExpertId unresolved on the assigned assessor profile.";
|
||||||
|
if (requireClaimExpertId) {
|
||||||
|
throw new BadRequestException({
|
||||||
|
code:
|
||||||
|
resolved.code ?? "FANAVARAN_EXPERTISE_CLAIM_EXPERT_ID_MISSING",
|
||||||
|
message,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
warnings.push(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!active?.parts?.length) {
|
if (!active?.parts?.length) {
|
||||||
warnings.push("No active damage expert reply with priced parts exists.");
|
warnings.push("No active damage expert reply with priced parts exists.");
|
||||||
@@ -5709,7 +5931,11 @@ export class ClaimRequestManagementService {
|
|||||||
if (!claimCase) throw new NotFoundException("Claim case not found");
|
if (!claimCase) throw new NotFoundException("Claim case not found");
|
||||||
|
|
||||||
const { payload, warnings, replyKey } =
|
const { payload, warnings, replyKey } =
|
||||||
await this.buildFanavaranExpertisePayload({ claimCase, clientKey });
|
await this.buildFanavaranExpertisePayload({
|
||||||
|
claimCase,
|
||||||
|
clientKey,
|
||||||
|
requireClaimExpertId: false,
|
||||||
|
});
|
||||||
|
|
||||||
await this.claimCaseDbService.findByIdAndUpdate(claimCaseId, {
|
await this.claimCaseDbService.findByIdAndUpdate(claimCaseId, {
|
||||||
$set: {
|
$set: {
|
||||||
@@ -5728,7 +5954,7 @@ export class ClaimRequestManagementService {
|
|||||||
submitUrl: claimCase.claimId
|
submitUrl: claimCase.claimId
|
||||||
? `${await this.fanavaranClaimsUrlForClaim(claimCaseId)}/${claimCase.claimId}/expertise`
|
? `${await this.fanavaranClaimsUrlForClaim(claimCaseId)}/${claimCase.claimId}/expertise`
|
||||||
: null,
|
: null,
|
||||||
ready: warnings.length === 0,
|
ready: warnings.length === 0 && payload.ClaimExpertId != null,
|
||||||
warnings: Array.from(new Set(warnings)),
|
warnings: Array.from(new Set(warnings)),
|
||||||
payload,
|
payload,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -104,4 +104,29 @@ describe("Fanavaran assigned ClaimExpertId resolution", () => {
|
|||||||
}),
|
}),
|
||||||
).rejects.toBeInstanceOf(BadRequestException);
|
).rejects.toBeInstanceOf(BadRequestException);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("preview soft-resolve returns null plus a concrete warning instead of throwing", async () => {
|
||||||
|
const management = serviceWithStaff({});
|
||||||
|
await expect(
|
||||||
|
(management as any).resolveFanavaranBaseClaimExpertId(
|
||||||
|
{
|
||||||
|
type: BlameRequestType.THIRD_PARTY,
|
||||||
|
expert: { assignedExpertId: "missing" },
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
{ required: false },
|
||||||
|
),
|
||||||
|
).resolves.toBeNull();
|
||||||
|
|
||||||
|
const soft = await (management as any).tryResolveFanavaranBaseClaimExpertId(
|
||||||
|
{
|
||||||
|
type: BlameRequestType.THIRD_PARTY,
|
||||||
|
expert: { assignedExpertId: "missing" },
|
||||||
|
},
|
||||||
|
);
|
||||||
|
expect(soft.claimExpertId).toBeNull();
|
||||||
|
expect(soft.code).toBe("FANAVARAN_CLAIM_EXPERT_ID_MISSING");
|
||||||
|
expect(soft.message).toMatch(/ThirdPartyClaimExpertId/);
|
||||||
|
expect(soft.candidatesTried).toEqual(["missing"]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -561,6 +561,16 @@ export function localizeErrorMessage(
|
|||||||
return "این عملیات در مرحله فعلی پرونده امکانپذیر نیست. پرونده را دوباره باز کنید و مرحله جاری را بررسی کنید.";
|
return "این عملیات در مرحله فعلی پرونده امکانپذیر نیست. پرونده را دوباره باز کنید و مرحله جاری را بررسی کنید.";
|
||||||
if (/file.*required|video.*required|image.*required/i.test(message))
|
if (/file.*required|video.*required|image.*required/i.test(message))
|
||||||
return "فایل لازم برای این مرحله را بارگذاری کنید.";
|
return "فایل لازم برای این مرحله را بارگذاری کنید.";
|
||||||
|
if (
|
||||||
|
/ClaimExpertId unresolved|ThirdPartyClaimExpertId|CarBodyClaimExpertId|ThirdPartyExpertiseClaim|CarBodyExpertiseClaim/i.test(
|
||||||
|
message,
|
||||||
|
)
|
||||||
|
) {
|
||||||
|
if (/Expertise ClaimExpertId|expertise claim expert|FileReviewer/i.test(message)) {
|
||||||
|
return "کد کارشناس ارزیاب فناوران (ClaimExpertId مرحله کارشناسی) روی پروفایل کارشناس اختصاصیافته تنظیم نشده است. ThirdPartyExpertiseClaim یا CarBodyExpertiseClaim را در مدیریت کارکنان تنظیم کنید.";
|
||||||
|
}
|
||||||
|
return "کد کارشناس مسئول پرونده فناوران (ClaimExpertId) روی پروفایل کارشناس اختصاصیافته تنظیم نشده است. ThirdPartyClaimExpertId یا CarBodyClaimExpertId را در مدیریت کارکنان تنظیم کنید.";
|
||||||
|
}
|
||||||
if (
|
if (
|
||||||
/fanavaran.*(?:missing|required|failed)|policyid.*required/i.test(message)
|
/fanavaran.*(?:missing|required|failed)|policyid.*required/i.test(message)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -152,9 +152,14 @@ describe("Expert Fanavaran stage fields", () => {
|
|||||||
management.resolveAccidentVehicleUsedFromApis = jest
|
management.resolveAccidentVehicleUsedFromApis = jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockResolvedValue({ usedId: 1 });
|
.mockResolvedValue({ usedId: 1 });
|
||||||
management.resolveFanavaranBaseClaimExpertId = jest
|
management.tryResolveFanavaranBaseClaimExpertId = jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockResolvedValue(154);
|
.mockResolvedValue({
|
||||||
|
claimExpertId: 154,
|
||||||
|
code: null,
|
||||||
|
message: null,
|
||||||
|
candidatesTried: ["expert-1"],
|
||||||
|
});
|
||||||
management.enrichCarBodyHullBaseClaimPayload = jest
|
management.enrichCarBodyHullBaseClaimPayload = jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockImplementation(async ({ payload }) => {
|
.mockImplementation(async ({ payload }) => {
|
||||||
@@ -164,6 +169,7 @@ describe("Expert Fanavaran stage fields", () => {
|
|||||||
const payload = await management.previewFanavaranSubmitV2(id, clientKey, {
|
const payload = await management.previewFanavaranSubmitV2(id, clientKey, {
|
||||||
persistPayload: false,
|
persistPayload: false,
|
||||||
forceRefreshPolicy: false,
|
forceRefreshPolicy: false,
|
||||||
|
requireClaimExpertId: false,
|
||||||
});
|
});
|
||||||
expect(payload.ClaimExpertId).toBe(154);
|
expect(payload.ClaimExpertId).toBe(154);
|
||||||
expect(payload).toMatchObject({
|
expect(payload).toMatchObject({
|
||||||
@@ -234,15 +240,21 @@ describe("Expert Fanavaran stage fields", () => {
|
|||||||
management.blameRequestDbService = {
|
management.blameRequestDbService = {
|
||||||
findById: jest.fn().mockResolvedValue({ type: "THIRD_PARTY" }),
|
findById: jest.fn().mockResolvedValue({ type: "THIRD_PARTY" }),
|
||||||
};
|
};
|
||||||
management.resolveFanavaranExpertiseClaimExpertId = jest
|
management.tryResolveFanavaranExpertiseClaimExpertId = jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockResolvedValue(29);
|
.mockResolvedValue({
|
||||||
|
claimExpertId: 29,
|
||||||
|
code: null,
|
||||||
|
message: null,
|
||||||
|
candidatesTried: ["dmg-1"],
|
||||||
|
});
|
||||||
management.resolveFanavaranClaimProduct = jest
|
management.resolveFanavaranClaimProduct = jest
|
||||||
.fn()
|
.fn()
|
||||||
.mockResolvedValue("third-party");
|
.mockResolvedValue("third-party");
|
||||||
const result = await management.buildFanavaranExpertisePayload({
|
const result = await management.buildFanavaranExpertisePayload({
|
||||||
claimCase: claim,
|
claimCase: claim,
|
||||||
clientKey: "parsian",
|
clientKey: "parsian",
|
||||||
|
requireClaimExpertId: false,
|
||||||
});
|
});
|
||||||
expect(result.payload).toMatchObject({
|
expect(result.payload).toMatchObject({
|
||||||
InspectionPlaceId: 283,
|
InspectionPlaceId: 283,
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ export class FanavaranController {
|
|||||||
@ApiOperation({
|
@ApiOperation({
|
||||||
summary: "Preview Fanavaran base claim create payload",
|
summary: "Preview Fanavaran base claim create payload",
|
||||||
description:
|
description:
|
||||||
"GET has no request body. Always rebuilds GEN.03 from live policy + VIN/vehicle inquiries. Does not reuse fanavaranSync lastPayload / PolicyId / UsedId cache. Auth token is still shared until Asia/Tehran midnight.",
|
"GET has no request body. Always rebuilds GEN.03 from live policy + VIN/vehicle inquiries. Does not reuse fanavaranSync lastPayload / PolicyId / UsedId cache. Missing staff ClaimExpertId does not fail the preview — it returns ClaimExpertId=null plus previewWarnings with the exact missing field/staff. Auth token is still shared until Asia/Tehran midnight.",
|
||||||
})
|
})
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
name: "client",
|
name: "client",
|
||||||
@@ -102,6 +102,7 @@ export class FanavaranController {
|
|||||||
forceRefreshPolicy: true,
|
forceRefreshPolicy: true,
|
||||||
forceRefreshUsedId: true,
|
forceRefreshUsedId: true,
|
||||||
requirePolicyId: false,
|
requirePolicyId: false,
|
||||||
|
requireClaimExpertId: false,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user