Fix 'something went wrong' error when non-existing signer attempts to sign the document

This commit is contained in:
prafull-opensignlabs
2024-10-10 17:13:22 +05:30
parent 19d96230cd
commit 51031878eb
11 changed files with 31 additions and 253633 deletions
@@ -20,6 +20,7 @@ async function GetPublicTemplate(request) {
templatQuery.descending('updatedAt');
templatQuery.equalTo('IsPublic', true);
templatQuery.notEqualTo('IsArchive', true);
templatQuery.include('ExtUserPtr.TenantId');
const getTemplate = await templatQuery.find({ useMasterKey: true });
const extcls = new Parse.Query('contracts_Users');
extcls.equalTo('Email', user.get('email'));
@@ -31,7 +31,13 @@ const saveRoleContact = async contact => {
contactQuery.set('CreatedBy', contact.CreatedBy);
contactQuery.set('UserId', contact.UserId);
contactQuery.set('UserRole', 'contracts_Guest');
contactQuery.set('TenantId', contact.TenantId);
if (contact?.TenantId) {
contactQuery.set('TenantId', {
__type: 'Pointer',
className: 'partners_Tenant',
objectId: contact.TenantId,
});
}
contactQuery.set('IsDeleted', false);
const acl = new Parse.ACL();
acl.setReadAccess(contact.CreatedBy.objectId, true);
@@ -256,6 +262,7 @@ export default async function PublicUserLinkContactToDoc(req) {
// Execute the query to get the template with the specified 'templateid'
const docQuery = new Parse.Query('contracts_Template');
docQuery.include('ExtUserPtr');
docQuery.include('ExtUserPtr.TenantId');
const tempRes = await docQuery.get(templateid, { useMasterKey: true });
// Check if the template was found; if not, throw an error indicating the template was not found
if (!tempRes) {
@@ -317,7 +324,7 @@ export default async function PublicUserLinkContactToDoc(req) {
Email: email,
Phone: _extUser?.Phone ? _extUser.Phone : '',
CreatedBy: _tempRes.CreatedBy,
TenantId: _tempRes.ExtUserPtr.TenantId,
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
};
const template_json = JSON.parse(JSON.stringify(tempRes));
// if user present on platform create contact on the basis of extended user details
@@ -344,7 +351,7 @@ export default async function PublicUserLinkContactToDoc(req) {
Email: email,
Phone: phone,
CreatedBy: _tempRes.CreatedBy,
TenantId: _tempRes.ExtUserPtr.TenantId,
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
};
const template_json = JSON.parse(JSON.stringify(tempRes));
// Create new contract on the basis provided contact details by user and userId from _User class
@@ -381,7 +388,7 @@ export default async function PublicUserLinkContactToDoc(req) {
Email: email,
Phone: phone,
CreatedBy: _tempRes.CreatedBy,
TenantId: _tempRes.ExtUserPtr.TenantId,
TenantId: _tempRes.ExtUserPtr?.TenantId?.objectId,
};
const template_json = JSON.parse(JSON.stringify(tempRes));
// Create new contract on the basis provided contact details by user and userId from _User class
@@ -44,6 +44,7 @@ export default async function TemplateAfterSave(request) {
const Query = new Parse.Query('contracts_Template');
Query.include('Signers');
Query.include('CreatedBy');
Query.include('ExtUserPtr.TenantId');
const updateACL = await Query.get(objId, { useMasterKey: true });
const res = JSON.parse(JSON.stringify(updateACL));
// console.log("res");
@@ -85,6 +86,7 @@ export default async function TemplateAfterSave(request) {
const Query = new Parse.Query('contracts_Template');
Query.include('CreatedBy');
Query.include('ExtUserPtr.TenantId');
const updateACL = await Query.get(objId, { useMasterKey: true });
const res = JSON.parse(JSON.stringify(updateACL));
// console.log("res");
@@ -29,7 +29,13 @@ const saveRoleContact = async contact => {
contactQuery.set('CreatedBy', contact.CreatedBy);
contactQuery.set('UserId', contact.UserId);
contactQuery.set('UserRole', 'contracts_Guest');
contactQuery.set('TenantId', contact.TenantId);
if (contact?.TenantId) {
contactQuery.set('TenantId', {
__type: 'Pointer',
className: 'partners_Tenant',
objectId: contact.TenantId,
});
}
contactQuery.set('IsDeleted', false);
const acl = new Parse.ACL();
acl.setReadAccess(contact.CreatedBy.objectId, true);
@@ -125,7 +131,7 @@ export default async function linkContactToDoc(req) {
Email: email,
Phone: _extUser?.Phone ? _extUser.Phone : '',
CreatedBy: _docRes.CreatedBy,
TenantId: _docRes.ExtUserPtr.TenantId,
TenantId: _docRes.ExtUserPtr?.TenantId?.objectId,
};
// if user present on platform create contact on the basis of extended user details
const contactRes = await saveRoleContact(contact);
@@ -177,7 +183,7 @@ export default async function linkContactToDoc(req) {
Email: email,
Phone: phone,
CreatedBy: _docRes.CreatedBy,
TenantId: _docRes.ExtUserPtr.TenantId,
TenantId: _docRes.ExtUserPtr?.TenantId?.objectId,
};
// Create new contract on the basis provided contact details by user and userId from _User class
const contactRes = await saveRoleContact(contact);
@@ -234,7 +240,7 @@ export default async function linkContactToDoc(req) {
Email: email,
Phone: phone,
CreatedBy: _docRes.CreatedBy,
TenantId: _docRes.ExtUserPtr.TenantId,
TenantId: _docRes.ExtUserPtr?.TenantId?.objectId,
};
// Create new contract on the basis provided contact details by user and userId from _User class
const contactRes = await saveRoleContact(contact);
@@ -274,7 +280,7 @@ export default async function linkContactToDoc(req) {
}
}
} catch (err) {
console.log('Err', err);
console.log('Err while creating contact link to doc', err);
}
} else {
throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, 'User not found.');