feat: send completed mail to all signers

This commit is contained in:
prafull-opensignlabs
2024-10-10 12:50:26 +05:30
parent 9c1b4261dc
commit 2a3947ea1d
19 changed files with 25 additions and 16 deletions
@@ -12,6 +12,7 @@ async function DocumentAftersave(request) {
const ExpiryDate = new Date(createdAt);
ExpiryDate.setDate(ExpiryDate.getDate() + TimeToCompleteDays);
const documentQuery = new Parse.Query('contracts_Document');
documentQuery.include('ExtUserPtr.TenantId');
const updateQuery = await documentQuery.get(request.object.id, { useMasterKey: true });
updateQuery.set('ExpiryDate', ExpiryDate);
if (!originIp) {
@@ -30,6 +31,7 @@ async function DocumentAftersave(request) {
const ExpiryDate = new Date(createdAt);
ExpiryDate.setDate(ExpiryDate.getDate() + TimeToCompleteDays);
const documentQuery = new Parse.Query('contracts_Document');
documentQuery.include('ExtUserPtr.TenantId');
const updateQuery = await documentQuery.get(request.object.id, { useMasterKey: true });
updateQuery.set('ExpiryDate', ExpiryDate);
if (!originIp) {
@@ -76,6 +78,7 @@ async function DocumentAftersave(request) {
// console.log(objId)
const Query = new Parse.Query('contracts_Document');
Query.include('Signers');
Query.include('ExtUserPtr.TenantId');
Query.include('CreatedBy');
const updateACL = await Query.get(objId, { useMasterKey: true });
const res = JSON.parse(JSON.stringify(updateACL));
@@ -116,6 +119,7 @@ async function DocumentAftersave(request) {
// console.log(objId)
const Query = new Parse.Query('contracts_Document');
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");
@@ -99,7 +99,7 @@ const sendMailToAllSigners = async docId => {
try {
//get document details that recenlty created from public template
const docQuery = new Parse.Query('contracts_Document');
docQuery.include('ExtUserPtr');
docQuery.include('ExtUserPtr,ExtUserPtr.TenantId');
docQuery.include('Signers');
const docRes = await docQuery.get(docId, { useMasterKey: true });
const Doc = JSON.parse(JSON.stringify(docRes));
@@ -7,6 +7,7 @@ async function getDocument(docId) {
query.include('CreatedBy');
query.include('Signers');
query.include('AuditTrail.UserPtr');
query.include('ExtUserPtr.TenantId');
query.include('Placeholders');
query.notEqualTo('IsArchive', true);
const res = await query.first({ useMasterKey: true });
@@ -9,6 +9,7 @@ export default async function callWebhook(request) {
const appId = process.env.APP_ID;
try {
const docQuery = new Parse.Query('contracts_Document');
docQuery.include('ExtUserPtr.TenantId');
const docRes = await docQuery.get(docId, { useMasterKey: true });
const isEnableOTP = docRes?.get('IsEnableOTP') || false;
let userId;
@@ -9,6 +9,7 @@ export default async function declinedocument(request) {
try {
const docCls = new Parse.Query('contracts_Document');
docCls.include('ExtUserPtr.TenantId');
const updateDoc = await docCls.get(docId, { useMasterKey: true });
if (updateDoc) {
const isEnableOTP = updateDoc?.get('IsEnableOTP') || false;
@@ -18,9 +18,9 @@ export default async function getDrive(request) {
if (userId) {
let url;
if (docId) {
url = `${classUrl}?where={"Folder":{"__type":"Pointer","className":"contracts_Document","objectId":"${docId}"},"CreatedBy":{"__type":"Pointer","className":"_User","objectId":"${userId}"},"IsArchive":{"$ne":true}}&include=ExtUserPtr,Signers,Folder&order=-updatedAt&skip=${skip}&limit=${limit}`;
url = `${classUrl}?where={"Folder":{"__type":"Pointer","className":"contracts_Document","objectId":"${docId}"},"CreatedBy":{"__type":"Pointer","className":"_User","objectId":"${userId}"},"IsArchive":{"$ne":true}}&include=ExtUserPtr,ExtUserPtr.TenantId,Signers,Folder&order=-updatedAt&skip=${skip}&limit=${limit}`;
} else {
url = `${classUrl}?where={"Folder":{"$exists":false},"CreatedBy":{"__type":"Pointer","className":"_User","objectId":"${userId}"},"IsArchive":{"$ne":true}}&include=ExtUserPtr,Signers&order=-updatedAt&skip=${skip}&limit=${limit}`;
url = `${classUrl}?where={"Folder":{"$exists":false},"CreatedBy":{"__type":"Pointer","className":"_User","objectId":"${userId}"},"IsArchive":{"$ne":true}}&include=ExtUserPtr,ExtUserPtr.TenantId,Signers&order=-updatedAt&skip=${skip}&limit=${limit}`;
}
try {
const res = await axios.get(url, {
@@ -52,11 +52,7 @@ export default async function getReport(request) {
} else {
strParams = JSON.stringify({
...params,
CreatedBy: {
__type: 'Pointer',
className: '_User',
objectId: userId,
},
CreatedBy: { __type: 'Pointer', className: '_User', objectId: userId },
});
}
}
@@ -66,7 +62,7 @@ export default async function getReport(request) {
'X-Parse-Application-Id': appId,
'X-Parse-Master-Key': masterKey,
};
const url = `${serverUrl}/classes/${clsName}?where=${strParams}&keys=${strKeys}&order=${orderBy}&skip=${skip}&limit=${limit}&include=AuditTrail.UserPtr,Placeholders.signerPtr`;
const url = `${serverUrl}/classes/${clsName}?where=${strParams}&keys=${strKeys}&order=${orderBy}&skip=${skip}&limit=${limit}&include=AuditTrail.UserPtr,Placeholders.signerPtr,ExtUserPtr.TenantId`;
const res = await axios.get(url, { headers: headers });
if (res.data && res.data.results) {
return res.data.results;
@@ -54,7 +54,7 @@ export default async function linkContactToDoc(req) {
if (docId) {
// Execute the query to get the document with the specified 'docId'
const docQuery = new Parse.Query('contracts_Document');
docQuery.include('ExtUserPtr');
docQuery.include('ExtUserPtr,ExtUserPtr.TenantId');
const docRes = await docQuery.get(docId, { useMasterKey: true });
// Check if the document was found; if not, throw an error indicating the document was not found
if (!docRes) {
@@ -102,7 +102,8 @@ async function sendCompletedMail(obj) {
const sender = obj.doc.ExtUserPtr;
const pdfName = doc.Name;
const mailLogo = 'https://qikinnovation.ams3.digitaloceanspaces.com/logo.png';
const recipient = sender.Email;
const recipient =
doc?.Signers?.length > 0 ? doc?.Signers?.map(x => x?.Email)?.join(',') : sender.Email;
let subject = `Document "${pdfName}" has been signed by all parties`;
let body =
"<html><head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8' /></head><body> <div style='background-color:#f5f5f5;padding:20px'> <div style='box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;background-color:white;'> <div><img src=" +