mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-25 00:52:34 +02:00
@@ -1,4 +1,4 @@
|
||||
export const setDocumentCount = async (extUserId, docsCount) => {
|
||||
export const setDocumentCount = async extUserId => {
|
||||
if (extUserId) {
|
||||
try {
|
||||
// Update count in contracts_Users class
|
||||
@@ -6,14 +6,7 @@ export const setDocumentCount = async (extUserId, docsCount) => {
|
||||
extQuery.equalTo('objectId', extUserId);
|
||||
const contractUser = await extQuery.first({ useMasterKey: true });
|
||||
if (contractUser) {
|
||||
if (docsCount) {
|
||||
const count = contractUser.get('DocumentCount')
|
||||
? contractUser.get('DocumentCount') + Number(docsCount)
|
||||
: 0 + Number(docsCount);
|
||||
contractUser.set('DocumentCount', count);
|
||||
} else {
|
||||
contractUser.increment('DocumentCount', 1);
|
||||
}
|
||||
contractUser.increment('DocumentCount', 1);
|
||||
await contractUser.save(null, { useMasterKey: true });
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
// Workflow helpers for placeholder/audit-trail processing. These helpers
|
||||
// are intentionally agnostic of any role classification — they treat every
|
||||
// non-prefill placeholder as a participant, and only the 'Signed' activity
|
||||
// counts toward completion. Builds with role-aware behaviour layer extra
|
||||
// filtering on top.
|
||||
|
||||
// Audit-trail activities that mark a placeholder as having fulfilled its
|
||||
// completion duty.
|
||||
export const COMPLETION_ACTIVITIES = ['Signed'];
|
||||
|
||||
// A placeholder participates in completion unless it is a prefill entry
|
||||
// (which only pre-populates field values without acting on the document).
|
||||
export function isParticipantBasic(placeholder) {
|
||||
return placeholder?.Role !== 'prefill';
|
||||
}
|
||||
|
||||
// A placeholder participates in completion unless it is a prefill entry or a viewer.
|
||||
export function isCompletionRelevant(placeholder) {
|
||||
if (!isParticipantBasic(placeholder)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
// Locate a placeholder index by signerObjId. Prefill placeholders are
|
||||
// excluded so caller indices stay aligned with the participant list.
|
||||
export function findPlaceholderIndex(placeholders, signerObjId) {
|
||||
if (!Array.isArray(placeholders) || !signerObjId) return -1;
|
||||
return placeholders.findIndex(
|
||||
p => (p?.signerObjId || p?.signerPtr?.objectId) === signerObjId && p?.Role !== 'prefill'
|
||||
);
|
||||
}
|
||||
|
||||
// Strict-order gating: returns the signerObjId of the prior placeholder
|
||||
// still pending, or null when the strict-order requirement is satisfied.
|
||||
export function findPendingPriorSigner(placeholders, idx, auditTrail) {
|
||||
if (!Array.isArray(placeholders) || idx <= 0) return null;
|
||||
const trail = Array.isArray(auditTrail) ? auditTrail : [];
|
||||
for (let i = 0; i < idx; i++) {
|
||||
const ph = placeholders[i];
|
||||
if (!isCompletionRelevant(ph)) continue;
|
||||
const signerObjId = ph?.signerObjId || ph?.signerPtr?.objectId;
|
||||
if (!signerObjId) continue;
|
||||
const acted = trail.some(
|
||||
a => a?.UserPtr?.objectId === signerObjId && COMPLETION_ACTIVITIES.includes(a?.Activity)
|
||||
);
|
||||
if (!acted) return signerObjId;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user