forked from Yara724/api
YARA-951 case-4
This commit is contained in:
@@ -28,6 +28,12 @@ import {
|
||||
ExpertFileAssignResultDto,
|
||||
ExpertFileAssignStatus,
|
||||
} from "src/common/dto/expert-file-assign-result.dto";
|
||||
import {
|
||||
BLAME_REVIEW_ASSIGNED_HISTORY_TYPE,
|
||||
blameWorkflowAssigneeToPersistOnLockExpiry,
|
||||
buildExpertAssignConflictForOtherReviewer,
|
||||
resolvePersistentReviewAssigneeId,
|
||||
} from "src/helpers/expert-workflow-review-assignee";
|
||||
import { RequestManagementDbService } from "src/request-management/entities/db-service/request-management.db.service";
|
||||
import { BlameRequestDbService } from "src/request-management/entities/db-service/blame-request.db.service";
|
||||
import {
|
||||
@@ -541,10 +547,18 @@ export class ExpertBlameService {
|
||||
);
|
||||
}
|
||||
|
||||
const assigneeToPersist = blameWorkflowAssigneeToPersistOnLockExpiry(
|
||||
request.workflow,
|
||||
);
|
||||
const expireSet: Record<string, unknown> = { "workflow.locked": false };
|
||||
if (assigneeToPersist) {
|
||||
expireSet["workflow.assignedForReviewBy"] = assigneeToPersist;
|
||||
}
|
||||
|
||||
const cleared = await this.blameRequestDbService.findOneAndUpdate(
|
||||
filter as any,
|
||||
{
|
||||
$set: { "workflow.locked": false },
|
||||
$set: expireSet,
|
||||
$unset: {
|
||||
"workflow.lockedAt": "",
|
||||
"workflow.expiredAt": "",
|
||||
@@ -1056,24 +1070,29 @@ export class ExpertBlameService {
|
||||
}
|
||||
|
||||
const expertOid = new Types.ObjectId(actor.sub);
|
||||
const reviewAssigneeId = resolvePersistentReviewAssigneeId(
|
||||
request.workflow,
|
||||
request.history,
|
||||
BLAME_REVIEW_ASSIGNED_HISTORY_TYPE,
|
||||
);
|
||||
if (reviewAssigneeId && reviewAssigneeId !== actor.sub) {
|
||||
throw new ConflictException(
|
||||
buildExpertAssignConflictForOtherReviewer(
|
||||
reviewAssigneeId,
|
||||
request.workflow,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
const lockedById = String(request.workflow?.lockedBy?.actorId ?? "");
|
||||
const lockEnforced =
|
||||
request.workflow?.locked &&
|
||||
this.isBlameV2WorkflowLockCurrentlyEnforced(request);
|
||||
|
||||
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: request.workflow?.lockedBy?.actorName,
|
||||
lockedAt: request.workflow?.lockedAt
|
||||
? new Date(request.workflow.lockedAt as Date).toISOString()
|
||||
: undefined,
|
||||
},
|
||||
});
|
||||
throw new ConflictException(
|
||||
buildExpertAssignConflictForOtherReviewer(lockedById, request.workflow),
|
||||
);
|
||||
}
|
||||
|
||||
if (lockEnforced && lockedById === actor.sub) {
|
||||
@@ -1089,17 +1108,21 @@ export class ExpertBlameService {
|
||||
|
||||
const now = new Date();
|
||||
const lockSnapshot = await this.snapshotFieldExpert(actor.sub);
|
||||
const lockUpdate = {
|
||||
const lockedByPayload = {
|
||||
actorId: expertOid,
|
||||
actorName: actor.fullName || "Unknown Expert",
|
||||
actorRole: "expert" as const,
|
||||
...(lockSnapshot && { expertProfileSnapshot: lockSnapshot }),
|
||||
};
|
||||
const lockUpdate: {
|
||||
$set: Record<string, unknown>;
|
||||
$push: Record<string, unknown>;
|
||||
} = {
|
||||
$set: {
|
||||
"workflow.locked": true,
|
||||
"workflow.lockedAt": now,
|
||||
"workflow.expiredAt": new Date(now.getTime() + this.blameV2LockTtlMs),
|
||||
"workflow.lockedBy": {
|
||||
actorId: expertOid,
|
||||
actorName: actor.fullName || "Unknown Expert",
|
||||
actorRole: "expert",
|
||||
...(lockSnapshot && { expertProfileSnapshot: lockSnapshot }),
|
||||
},
|
||||
"workflow.lockedBy": lockedByPayload,
|
||||
},
|
||||
$push: {
|
||||
history: {
|
||||
@@ -1114,16 +1137,30 @@ export class ExpertBlameService {
|
||||
},
|
||||
},
|
||||
};
|
||||
if (!request.workflow?.assignedForReviewBy) {
|
||||
lockUpdate.$set["workflow.assignedForReviewBy"] = lockedByPayload;
|
||||
}
|
||||
|
||||
const assignFilter: Record<string, unknown> = {
|
||||
_id: new Types.ObjectId(requestId),
|
||||
status: CaseStatus.WAITING_FOR_EXPERT,
|
||||
blameStatus: BlameStatus.DISAGREEMENT,
|
||||
$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 },
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
@@ -1140,6 +1177,19 @@ export class ExpertBlameService {
|
||||
if (!updated) {
|
||||
await this.expireBlameCaseWorkflowLockV2IfStale(requestId);
|
||||
const latest = await this.blameRequestDbService.findById(requestId);
|
||||
const otherAssigneeId = resolvePersistentReviewAssigneeId(
|
||||
latest?.workflow,
|
||||
latest?.history,
|
||||
BLAME_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 &&
|
||||
@@ -1147,18 +1197,9 @@ export class ExpertBlameService {
|
||||
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,
|
||||
|
||||
Reference in New Issue
Block a user