forked from Yara724/api
YARA-951 case-4
This commit is contained in:
@@ -35,6 +35,12 @@ import {
|
||||
ExpertFileAssignResultDto,
|
||||
ExpertFileAssignStatus,
|
||||
} from "src/common/dto/expert-file-assign-result.dto";
|
||||
import {
|
||||
CLAIM_REVIEW_ASSIGNED_HISTORY_TYPE,
|
||||
claimWorkflowAssigneeToPersistOnLockExpiry,
|
||||
buildExpertAssignConflictForOtherReviewer,
|
||||
resolvePersistentReviewAssigneeId,
|
||||
} from "src/helpers/expert-workflow-review-assignee";
|
||||
import { ClaimPerIdRs } from "./dto/claim-list-perId-rs.dto";
|
||||
import { ClaimListDtoRs } from "./dto/claim-list-rs.dto";
|
||||
import { ClaimCaseDbService } from "src/claim-request-management/entites/db-service/claim-case.db.service";
|
||||
@@ -2375,24 +2381,30 @@ export class ExpertClaimService {
|
||||
});
|
||||
}
|
||||
|
||||
const expertOid = new Types.ObjectId(actor.sub);
|
||||
const reviewAssigneeId = resolvePersistentReviewAssigneeId(
|
||||
claim.workflow,
|
||||
claim.history,
|
||||
CLAIM_REVIEW_ASSIGNED_HISTORY_TYPE,
|
||||
);
|
||||
if (reviewAssigneeId && reviewAssigneeId !== actor.sub) {
|
||||
throw new ConflictException(
|
||||
buildExpertAssignConflictForOtherReviewer(
|
||||
reviewAssigneeId,
|
||||
claim.workflow,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const lockedById = String(claim.workflow?.lockedBy?.actorId ?? "");
|
||||
const lockEnforced =
|
||||
claim.workflow?.locked &&
|
||||
this.isClaimV2WorkflowLockCurrentlyEnforced(claim);
|
||||
|
||||
if (lockEnforced && lockedById && lockedById !== actor.sub) {
|
||||
throw new ConflictException({
|
||||
success: false,
|
||||
status: "locked" satisfies ExpertFileAssignStatus,
|
||||
message: "Request is already being processed by another expert",
|
||||
lockedBy: {
|
||||
actorId: lockedById,
|
||||
actorName: claim.workflow?.lockedBy?.actorName,
|
||||
lockedAt: claim.workflow?.lockedAt
|
||||
? new Date(claim.workflow.lockedAt as Date).toISOString()
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
throw new ConflictException(
|
||||
buildExpertAssignConflictForOtherReviewer(lockedById, claim.workflow),
|
||||
);
|
||||
}
|
||||
|
||||
if (lockEnforced && lockedById === actor.sub) {
|
||||
@@ -2406,21 +2418,22 @@ export class ExpertClaimService {
|
||||
};
|
||||
}
|
||||
|
||||
const expertOid = new Types.ObjectId(actor.sub);
|
||||
const now = new Date();
|
||||
const lockSnapshot = await this.snapshotDamageExpert(actor.sub);
|
||||
const expiredAt = new Date(now.getTime() + this.claimV2WorkflowLockTtlMs);
|
||||
|
||||
const lockedByPayload = {
|
||||
actorId: expertOid,
|
||||
actorName: actor.fullName,
|
||||
actorRole: "damage_expert" as const,
|
||||
...(lockSnapshot && { expertProfileSnapshot: lockSnapshot }),
|
||||
};
|
||||
|
||||
const baseLockUpdate: Record<string, unknown> = {
|
||||
"workflow.locked": true,
|
||||
"workflow.lockedAt": now,
|
||||
"workflow.expiredAt": expiredAt,
|
||||
"workflow.lockedBy": {
|
||||
actorId: expertOid,
|
||||
actorName: actor.fullName,
|
||||
actorRole: "damage_expert",
|
||||
...(lockSnapshot && { expertProfileSnapshot: lockSnapshot }),
|
||||
},
|
||||
"workflow.lockedBy": lockedByPayload,
|
||||
"workflow.preLockQueueSnapshot": {
|
||||
claimStatus: claim.claimStatus,
|
||||
currentStep: this.normalizeClaimWorkflowStepForSnapshot(
|
||||
@@ -2455,6 +2468,10 @@ export class ExpertClaimService {
|
||||
},
|
||||
};
|
||||
|
||||
if (!claim.workflow?.assignedForReviewBy) {
|
||||
baseLockUpdate["workflow.assignedForReviewBy"] = lockedByPayload;
|
||||
}
|
||||
|
||||
const lockUpdate: Record<string, unknown> = isFactorValidationLock
|
||||
? baseLockUpdate
|
||||
: {
|
||||
@@ -2466,11 +2483,22 @@ export class ExpertClaimService {
|
||||
|
||||
const assignFilter: Record<string, unknown> = {
|
||||
_id: new Types.ObjectId(claimRequestId),
|
||||
$or: [
|
||||
{ "workflow.locked": { $ne: true } },
|
||||
{ "workflow.locked": false },
|
||||
{ "workflow.expiredAt": { $lte: now } },
|
||||
{ "workflow.lockedBy.actorId": expertOid },
|
||||
$and: [
|
||||
{
|
||||
$or: [
|
||||
{ "workflow.locked": { $ne: true } },
|
||||
{ "workflow.locked": false },
|
||||
{ "workflow.expiredAt": { $lte: now } },
|
||||
{ "workflow.lockedBy.actorId": expertOid },
|
||||
],
|
||||
},
|
||||
{
|
||||
$or: [
|
||||
{ "workflow.assignedForReviewBy": { $exists: false } },
|
||||
{ "workflow.assignedForReviewBy": null },
|
||||
{ "workflow.assignedForReviewBy.actorId": expertOid },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -2497,6 +2525,19 @@ export class ExpertClaimService {
|
||||
if (!updated) {
|
||||
await this.expireClaimWorkflowLockV2IfStale(claimRequestId);
|
||||
const latest = await this.claimCaseDbService.findById(claimRequestId);
|
||||
const otherAssigneeId = resolvePersistentReviewAssigneeId(
|
||||
latest?.workflow,
|
||||
latest?.history,
|
||||
CLAIM_REVIEW_ASSIGNED_HISTORY_TYPE,
|
||||
);
|
||||
if (otherAssigneeId && otherAssigneeId !== actor.sub) {
|
||||
throw new ConflictException(
|
||||
buildExpertAssignConflictForOtherReviewer(
|
||||
otherAssigneeId,
|
||||
latest?.workflow,
|
||||
),
|
||||
);
|
||||
}
|
||||
const otherId = String(latest?.workflow?.lockedBy?.actorId ?? "");
|
||||
if (
|
||||
latest?.workflow?.locked &&
|
||||
@@ -2504,18 +2545,9 @@ export class ExpertClaimService {
|
||||
otherId &&
|
||||
otherId !== actor.sub
|
||||
) {
|
||||
throw new ConflictException({
|
||||
success: false,
|
||||
status: "locked" satisfies ExpertFileAssignStatus,
|
||||
message: "Request is already being processed by another expert",
|
||||
lockedBy: {
|
||||
actorId: otherId,
|
||||
actorName: latest.workflow?.lockedBy?.actorName,
|
||||
lockedAt: latest.workflow?.lockedAt
|
||||
? new Date(latest.workflow.lockedAt as Date).toISOString()
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
throw new ConflictException(
|
||||
buildExpertAssignConflictForOtherReviewer(otherId, latest?.workflow),
|
||||
);
|
||||
}
|
||||
throw new BadRequestException({
|
||||
success: false,
|
||||
@@ -3657,10 +3689,18 @@ export class ExpertClaimService {
|
||||
"workflow.preLockQueueSnapshot": "",
|
||||
};
|
||||
|
||||
const assigneeToPersist = claimWorkflowAssigneeToPersistOnLockExpiry(
|
||||
claim.workflow,
|
||||
);
|
||||
const expireLockSet: Record<string, unknown> = { "workflow.locked": false };
|
||||
if (assigneeToPersist) {
|
||||
expireLockSet["workflow.assignedForReviewBy"] = assigneeToPersist;
|
||||
}
|
||||
|
||||
const update = needsQueueRestore
|
||||
? {
|
||||
$set: {
|
||||
"workflow.locked": false,
|
||||
...expireLockSet,
|
||||
status: ClaimCaseStatus.WAITING_FOR_DAMAGE_EXPERT,
|
||||
claimStatus: restoreClaimStatus,
|
||||
"workflow.currentStep": restoreCurrent,
|
||||
@@ -3669,7 +3709,7 @@ export class ExpertClaimService {
|
||||
$unset: lockFieldsUnset,
|
||||
}
|
||||
: {
|
||||
$set: { "workflow.locked": false },
|
||||
$set: expireLockSet,
|
||||
$unset: lockFieldsUnset,
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user