mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
New Features: 1. Added support to recreate a new document from declined document without having to redo everything from scratch. 2. Added replace pdf file feature for Templates. PDF underlying a Template can now be replaced while keeping all the fields the same. 3. Introduced the ability to replace pdf file for in UpdateTemplate and CreateDocumentfromtemplate API. 4. Revamped the preferences menu UI. Bug Fixes: 1. Fixed issue with capital letters in contact emails via API. 2. Better validations & error handling in APIs
37 lines
1.4 KiB
JavaScript
37 lines
1.4 KiB
JavaScript
export default async function recreateDocument(request) {
|
|
const { docId } = request.params;
|
|
if (!docId) {
|
|
throw new Parse.Error(Parse.Error.INVALID_QUERY, 'Missing docId parameter');
|
|
}
|
|
if (!request.user) {
|
|
throw new Parse.Error(Parse.Error.INVALID_SESSION_TOKEN, 'User not aunthenticated');
|
|
}
|
|
|
|
try {
|
|
const docQuery = new Parse.Query('contracts_Document');
|
|
docQuery.equalTo('objectId', docId);
|
|
const doc = await docQuery.first({ useMasterKey: true });
|
|
if (!doc) {
|
|
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'Document not found');
|
|
}
|
|
const _docRes = doc?.toJSON();
|
|
const { objectId, SignedUrl, AuditTrail, ACL, DeclineBy, DeclineReason, ...docRes } = _docRes;
|
|
const createDoc = new Parse.Object('contracts_Document');
|
|
Object.entries(docRes).forEach(([key, value]) => {
|
|
if (key === 'IsDeclined') {
|
|
createDoc.set(key, false);
|
|
} else {
|
|
createDoc.set(key, value);
|
|
}
|
|
// console.log(`${key}: ${value}`);
|
|
});
|
|
const createDocRes = await createDoc.save(null, { useMasterKey: true });
|
|
// console.log('createDocRes', createDocRes);
|
|
const newDoc = JSON.parse(JSON.stringify(createDocRes));
|
|
return { objectId: newDoc.objectId, createdAt: newDoc.createdAt, updatedAt: newDoc.updatedAt };
|
|
} catch (err) {
|
|
console.log('err in recreate document', err);
|
|
throw err;
|
|
}
|
|
}
|