1
0
forked from Yara724/api

Fixed lock

This commit is contained in:
SepehrYahyaee
2026-06-01 13:21:32 +03:30
parent fde6464739
commit 6261af8a29
3 changed files with 117 additions and 39 deletions

View File

@@ -25,9 +25,8 @@ export function resolvePersistentReviewAssigneeId(
if (fromField != null && String(fromField).length > 0) {
return String(fromField);
}
const fromHistory = history?.find(
(h) => h.type === assignedHistoryType,
)?.actor?.actorId;
const fromHistory = history?.find((h) => h.type === assignedHistoryType)
?.actor?.actorId;
if (fromHistory != null && String(fromHistory).length > 0) {
return String(fromHistory);
}
@@ -43,8 +42,7 @@ export function buildExpertAssignConflictForOtherReviewer(
message: string;
lockedBy: { actorId: string; actorName?: string; lockedAt?: string };
} {
const assignee =
workflow?.assignedForReviewBy ?? workflow?.lockedBy;
const assignee = workflow?.assignedForReviewBy ?? workflow?.lockedBy;
const lockedAt = workflow?.lockedAt;
return {
success: false,
@@ -53,25 +51,28 @@ export function buildExpertAssignConflictForOtherReviewer(
lockedBy: {
actorId: assigneeId,
actorName: assignee?.actorName,
lockedAt: lockedAt
? new Date(lockedAt as Date).toISOString()
: undefined,
lockedAt: lockedAt ? new Date(lockedAt as Date).toISOString() : undefined,
},
};
}
/** Copy lock holder into `assignedForReviewBy` when persisting a TTL unlock. */
export function blameWorkflowAssigneeToPersistOnLockExpiry(
workflow: WorkflowAssigneeRef | undefined,
): WorkflowAssigneeRef["assignedForReviewBy"] | undefined {
if (workflow?.assignedForReviewBy) {
return undefined;
}
return workflow?.lockedBy;
workflow: any,
request: any,
) {
const hasDecision = !!request?.expert?.decision;
return hasDecision ? (workflow?.assignedForReviewBy ?? null) : null;
}
export function claimWorkflowAssigneeToPersistOnLockExpiry(
workflow: WorkflowAssigneeRef | undefined,
): WorkflowAssigneeRef["assignedForReviewBy"] | undefined {
return blameWorkflowAssigneeToPersistOnLockExpiry(workflow);
workflow: any,
claim: any,
): typeof workflow.assignedForReviewBy | null {
// If a decision or resend was already submitted, preserve ownership
const hasDecision =
!!claim?.evaluation?.damageExpertReply ||
!!claim?.evaluation?.damageExpertReplyFinal ||
!!claim?.evaluation?.damageExpertResend;
return hasDecision ? (workflow?.assignedForReviewBy ?? null) : null;
}