mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-20 06:35:54 +02:00
Merge pull request #2460 from nxglabs/sync-to-public_repo-25861367352
Merge pull request #2459 from nxglabs/staging
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { setDocumentCount } from '../../utils/CountUtils.js';
|
||||
|
||||
export default async function recreateDocument(request) {
|
||||
const { docId } = request.params;
|
||||
if (!docId) {
|
||||
@@ -10,6 +12,16 @@ export default async function recreateDocument(request) {
|
||||
try {
|
||||
const docQuery = new Parse.Query('contracts_Document');
|
||||
docQuery.equalTo('objectId', docId);
|
||||
docQuery.notEqualTo('IsArchive', true);
|
||||
docQuery.exclude([
|
||||
'DocSentAt',
|
||||
'SignedUrl',
|
||||
'AuditTrail',
|
||||
'DeclineBy',
|
||||
'DeclineReason',
|
||||
'DocumentHash',
|
||||
'CertificateUrl',
|
||||
]);
|
||||
const doc = await docQuery.first({ useMasterKey: true });
|
||||
if (!doc) {
|
||||
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Document not found');
|
||||
@@ -18,11 +30,27 @@ export default async function recreateDocument(request) {
|
||||
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'Signyourself Document not allowed');
|
||||
}
|
||||
const _docRes = doc?.toJSON();
|
||||
const { objectId, SignedUrl, AuditTrail, ACL, DeclineBy, DeclineReason, ...docRes } = _docRes;
|
||||
const { ACL, objectId, ...docRes } = _docRes;
|
||||
const createDoc = new Parse.Object('contracts_Document');
|
||||
Object.entries(docRes).forEach(([key, value]) => {
|
||||
if (key === 'IsDeclined' || key === 'IsCompleted') {
|
||||
createDoc.set(key, false);
|
||||
} else if (key === 'Placeholders') {
|
||||
const placeHolders = value.map(signer => ({
|
||||
...signer,
|
||||
placeHolder: (signer.placeHolder || []).map(page => ({
|
||||
...page,
|
||||
pos: (page.pos || []).map(widget => {
|
||||
const { SignUrl, ...rest } = widget;
|
||||
return {
|
||||
...rest,
|
||||
type: widget.type === 'text' ? 'text input' : widget.type,
|
||||
options: { ...widget.options, response: '', defaultValue: '' },
|
||||
};
|
||||
}),
|
||||
})),
|
||||
}));
|
||||
createDoc.set(key, placeHolders);
|
||||
} else {
|
||||
createDoc.set(key, value);
|
||||
}
|
||||
@@ -31,6 +59,7 @@ export default async function recreateDocument(request) {
|
||||
const createDocRes = await createDoc.save(null, { useMasterKey: true });
|
||||
// console.log('createDocRes', createDocRes);
|
||||
const newDoc = JSON.parse(JSON.stringify(createDocRes));
|
||||
setDocumentCount(_docRes?.ExtUserPtr?.objectId);
|
||||
return { objectId: newDoc.objectId, createdAt: newDoc.createdAt, updatedAt: newDoc.updatedAt };
|
||||
} catch (err) {
|
||||
console.log('err in recreate document', err);
|
||||
|
||||
Reference in New Issue
Block a user