forked from Yara724/api
Fixed bugs
This commit is contained in:
@@ -2278,14 +2278,22 @@ export class ExpertClaimService {
|
||||
*
|
||||
* Validations:
|
||||
* - Claim must exist
|
||||
* - Status must be WAITING_FOR_DAMAGE_EXPERT
|
||||
* - Must not already be locked by another expert
|
||||
* - Status must be either:
|
||||
* • `WAITING_FOR_DAMAGE_EXPERT` (initial damage review queue), OR
|
||||
* • the factor-validation queue (`EXPERT_VALIDATING_REPAIR_FACTORS`,
|
||||
* or legacy `WAITING_FOR_INSURER_APPROVAL`, with
|
||||
* `claimStatus=UNDER_REVIEW` + `workflow.currentStep=EXPERT_COST_EVALUATION`).
|
||||
* - Must not already be locked by another expert.
|
||||
*
|
||||
* On success:
|
||||
* - Sets workflow.locked = true, workflow.lockedBy = actor
|
||||
* - Sets status = EXPERT_REVIEWING
|
||||
* - Sets claimStatus = UNDER_REVIEW
|
||||
* - Sets currentStep = EXPERT_DAMAGE_ASSESSMENT
|
||||
* - Always sets `workflow.locked=true`, `workflow.lockedBy=actor`,
|
||||
* `workflow.lockedAt/expiredAt`, and snapshots pre-lock queue state.
|
||||
* - For the **damage review** path: status → `EXPERT_REVIEWING`,
|
||||
* `claimStatus=UNDER_REVIEW`, `workflow.currentStep=EXPERT_DAMAGE_ASSESSMENT`.
|
||||
* - For the **factor-validation** path: leaves `status`, `claimStatus`, and
|
||||
* `workflow.currentStep` untouched so the claim stays in the factor-validation
|
||||
* queue (so `expireClaimWorkflowLockV2IfStale` and the queue endpoint keep
|
||||
* treating it correctly when the lock expires).
|
||||
*/
|
||||
async lockClaimRequestV2(claimRequestId: string, actor: any) {
|
||||
requireActorClientKey(actor);
|
||||
@@ -2298,7 +2306,11 @@ export class ExpertClaimService {
|
||||
|
||||
assertClaimCaseForTenant(claim, actor);
|
||||
|
||||
if (claim.status !== ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT) {
|
||||
const isFactorValidationLock = claimIsAwaitingExpertFactorValidationV2(claim);
|
||||
const isDamageReviewLock =
|
||||
claim.status === ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT;
|
||||
|
||||
if (!isDamageReviewLock && !isFactorValidationLock) {
|
||||
throw new BadRequestException(
|
||||
`Claim is not available for locking. Current status: ${claim.status}`,
|
||||
);
|
||||
@@ -2325,9 +2337,8 @@ export class ExpertClaimService {
|
||||
const lockAt = new Date();
|
||||
const expiredAt = new Date(lockAt.getTime() + this.claimV2WorkflowLockTtlMs);
|
||||
|
||||
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, {
|
||||
status: ClaimCaseStatus.EXPERT_REVIEWING,
|
||||
claimStatus: ClaimStatus.UNDER_REVIEW,
|
||||
// Common lock fields written in both branches.
|
||||
const baseLockUpdate: Record<string, unknown> = {
|
||||
'workflow.locked': true,
|
||||
'workflow.lockedAt': lockAt,
|
||||
'workflow.expiredAt': expiredAt,
|
||||
@@ -2352,7 +2363,6 @@ export class ExpertClaimService {
|
||||
}
|
||||
: {}),
|
||||
},
|
||||
'workflow.currentStep': ClaimWorkflowStep.EXPERT_DAMAGE_ASSESSMENT,
|
||||
$push: {
|
||||
history: {
|
||||
type: "CLAIM_LOCKED",
|
||||
@@ -2362,10 +2372,28 @@ export class ExpertClaimService {
|
||||
actorType: "damage_expert",
|
||||
},
|
||||
timestamp: new Date(),
|
||||
metadata: { note: `Claim locked by damage expert ${actor.fullName}` },
|
||||
metadata: {
|
||||
note: isFactorValidationLock
|
||||
? `Claim locked for factor validation by damage expert ${actor.fullName}`
|
||||
: `Claim locked by damage expert ${actor.fullName}`,
|
||||
...(isFactorValidationLock ? { phase: "factorValidation" } : {}),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
// Damage-review lock advances status/step; factor-validation lock keeps them
|
||||
// intact so the claim remains in the factor-validation queue when the lock expires.
|
||||
const update: Record<string, unknown> = isFactorValidationLock
|
||||
? baseLockUpdate
|
||||
: {
|
||||
...baseLockUpdate,
|
||||
status: ClaimCaseStatus.EXPERT_REVIEWING,
|
||||
claimStatus: ClaimStatus.UNDER_REVIEW,
|
||||
'workflow.currentStep': ClaimWorkflowStep.EXPERT_DAMAGE_ASSESSMENT,
|
||||
};
|
||||
|
||||
await this.claimCaseDbService.findByIdAndUpdate(claimRequestId, update);
|
||||
|
||||
await this.recordClaimExpertActivity({
|
||||
expertId: String(actor.sub),
|
||||
|
||||
Reference in New Issue
Block a user