mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-20 06:35:54 +02:00
add getReport cloud function
This commit is contained in:
@@ -27,7 +27,7 @@ export default async function getDrive(request) {
|
||||
'X-Parse-Master-key': process.env.MASTER_KEY,
|
||||
},
|
||||
});
|
||||
console.log('res.data.results ', res.data.results);
|
||||
// console.log('res.data.results ', res.data.results);
|
||||
if (res.data && res.data.results) {
|
||||
return res.data.results;
|
||||
} else {
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
import reportJson from './reportsJson.js';
|
||||
import axios from 'axios'
|
||||
|
||||
export default async function getReport(request) {
|
||||
const reportId = request.params.reportId;
|
||||
const limit = request.params.limit;
|
||||
const skip = request.params.skip;
|
||||
|
||||
const serverUrl = process.env.SERVER_URL;
|
||||
const appId = process.env.APP_ID;
|
||||
|
||||
try {
|
||||
const userRes = await axios.get(serverUrl + '/users/me', {
|
||||
headers: {
|
||||
'X-Parse-Application-Id': appId,
|
||||
'X-Parse-Session-Token': request.headers['sessiontoken'],
|
||||
},
|
||||
});
|
||||
const userId = userRes.data && userRes.data.objectId;
|
||||
if (userId) {
|
||||
const json = reportId && reportJson(reportId, userId);
|
||||
if (json) {
|
||||
const { params, keys } = json;
|
||||
const orderBy = '-updatedAt';
|
||||
const strParams = JSON.stringify(params);
|
||||
const strKeys = keys.join();
|
||||
const headers = {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Parse-Application-Id': appId,
|
||||
'X-Parse-Master-Key': process.env.MASTER_KEY,
|
||||
};
|
||||
const url = `${serverUrl}/classes/contracts_Document?where=${strParams}&keys=${strKeys}&order=${orderBy}&skip=${skip}&limit=${limit}&include=AuditTrail.UserPtr`;
|
||||
const res = await axios.get(url, { headers: headers });
|
||||
if (res.data && res.data.results) {
|
||||
return res.data.results;
|
||||
} else {
|
||||
return [];
|
||||
}
|
||||
} else {
|
||||
return { error: 'Report is not available!' };
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
console.log('err', err);
|
||||
if (err.code == 209) {
|
||||
return { error: 'Invalid session token' };
|
||||
} else {
|
||||
return { error: "You don't have access!" };
|
||||
}
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -105,7 +105,7 @@ async function PDF(s, r) {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'X-Parse-Application-Id': APPID,
|
||||
'X-Parse-Session-Token': s.headers.sessiontoken,
|
||||
'X-Parse-Master-Key': masterKEY,
|
||||
},
|
||||
}),
|
||||
d = await axios.get(serverUrl + '/users/me', {
|
||||
|
||||
@@ -0,0 +1,204 @@
|
||||
export default function reportJson(id, userId) {
|
||||
const currentUserId = userId;
|
||||
|
||||
switch (id) {
|
||||
// draft documents report
|
||||
case 'ByHuevtCFY':
|
||||
return {
|
||||
reportName: 'Draft Documents',
|
||||
params: {
|
||||
Type: null,
|
||||
$or: [
|
||||
{ Signers: null, SignedUrl: null },
|
||||
{ Signers: { $exists: true }, Placeholders: null },
|
||||
],
|
||||
CreatedBy: {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: currentUserId,
|
||||
},
|
||||
},
|
||||
keys: ['Name', 'Note', 'Folder.Name', 'URL', 'ExtUserPtr.Name', 'Signers.Name'],
|
||||
};
|
||||
// Need your sign report
|
||||
case '4Hhwbp482K':
|
||||
return {
|
||||
reportName: 'Need your sign',
|
||||
params: {
|
||||
Type: { $ne: 'Folder' },
|
||||
IsCompleted: { $ne: true },
|
||||
IsDeclined: { $ne: true },
|
||||
ExpiryDate: {
|
||||
$gt: { __type: 'Date', iso: new Date().toISOString() },
|
||||
},
|
||||
Placeholders: { $ne: null },
|
||||
},
|
||||
keys: [
|
||||
'Name',
|
||||
'Note',
|
||||
'Folder.Name',
|
||||
'URL',
|
||||
'ExtUserPtr.Name',
|
||||
'Signers.Name',
|
||||
'Signers.UserId',
|
||||
'AuditTrail',
|
||||
],
|
||||
};
|
||||
// In progess report
|
||||
case '1MwEuxLEkF':
|
||||
return {
|
||||
reportName: 'In-progress documents',
|
||||
params: {
|
||||
Type: { $ne: 'Folder' },
|
||||
Signers: { $ne: null },
|
||||
Placeholders: { $ne: null },
|
||||
IsCompleted: { $ne: true },
|
||||
IsDeclined: { $ne: true },
|
||||
CreatedBy: {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: currentUserId,
|
||||
},
|
||||
ExpiryDate: {
|
||||
$gt: { __type: 'Date', iso: new Date().toISOString() },
|
||||
},
|
||||
},
|
||||
keys: ['Name', 'Note', 'Folder.Name', 'URL', 'ExtUserPtr.Name', 'Signers.Name'],
|
||||
};
|
||||
// completed documents report
|
||||
case 'kQUoW4hUXz':
|
||||
return {
|
||||
reportName: 'Completed Documents',
|
||||
params: {
|
||||
Type: null,
|
||||
IsCompleted: true,
|
||||
CreatedBy: {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: currentUserId,
|
||||
},
|
||||
IsDeclined: { $ne: true },
|
||||
},
|
||||
keys: [
|
||||
'Name',
|
||||
'Note',
|
||||
'Folder.Name',
|
||||
'URL',
|
||||
'ExtUserPtr.Name',
|
||||
'Signers.Name',
|
||||
'TimeToCompleteDays',
|
||||
],
|
||||
};
|
||||
|
||||
// declined documents report
|
||||
case 'UPr2Fm5WY3':
|
||||
return {
|
||||
reportName: 'Declined Documents',
|
||||
params: {
|
||||
Type: null,
|
||||
IsDeclined: true,
|
||||
CreatedBy: {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: currentUserId,
|
||||
},
|
||||
},
|
||||
|
||||
keys: ['Name', 'Note', 'Folder.Name', 'URL', 'ExtUserPtr.Name', 'Signers.Name'],
|
||||
};
|
||||
// Expired Documents report
|
||||
case 'zNqBHXHsYH':
|
||||
return {
|
||||
reportName: 'Expired Documents',
|
||||
params: {
|
||||
IsCompleted: { $ne: true },
|
||||
IsDeclined: { $ne: true },
|
||||
Type: { $ne: 'Folder' },
|
||||
$and: [
|
||||
{
|
||||
$or: [
|
||||
{ Signers: { $ne: null }, SignedUrl: { $ne: null } },
|
||||
{ Placeholders: { $ne: null } },
|
||||
],
|
||||
},
|
||||
{
|
||||
ExpiryDate: {
|
||||
$lt: { __type: 'Date', iso: new Date().toISOString() },
|
||||
},
|
||||
},
|
||||
],
|
||||
CreatedBy: {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: currentUserId,
|
||||
},
|
||||
},
|
||||
keys: ['Name', 'Note', 'Folder.Name', 'URL', 'ExtUserPtr.Name', 'Signers.Name'],
|
||||
};
|
||||
// Recently sent for signatures report show on dashboard
|
||||
case 'd9k3UfYHBc':
|
||||
return {
|
||||
reportName: 'Recently sent for signatures',
|
||||
params: {
|
||||
Type: { $ne: 'Folder' },
|
||||
Signers: { $ne: null },
|
||||
Placeholders: { $ne: null },
|
||||
IsCompleted: { $ne: true },
|
||||
IsDeclined: { $ne: true },
|
||||
CreatedBy: {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: currentUserId,
|
||||
},
|
||||
ExpiryDate: {
|
||||
$gt: { __type: 'Date', iso: new Date().toISOString() },
|
||||
},
|
||||
},
|
||||
keys: ['Name', 'Note', 'Folder.Name', 'URL', 'ExtUserPtr.Name', 'Signers.Name'],
|
||||
};
|
||||
// Recent signature requests report show on dashboard
|
||||
case '5Go51Q7T8r':
|
||||
return {
|
||||
reportName: 'Recent signature requests',
|
||||
params: {
|
||||
Type: { $ne: 'Folder' },
|
||||
IsCompleted: { $ne: true },
|
||||
IsDeclined: { $ne: true },
|
||||
ExpiryDate: {
|
||||
$gt: { __type: 'Date', iso: new Date().toISOString() },
|
||||
},
|
||||
Placeholders: { $ne: null },
|
||||
},
|
||||
keys: [
|
||||
'Name',
|
||||
'Note',
|
||||
'Folder.Name',
|
||||
'URL',
|
||||
'ExtUserPtr.Name',
|
||||
'Signers.Name',
|
||||
'Signers.UserId',
|
||||
'AuditTrail',
|
||||
],
|
||||
};
|
||||
// Drafts report show on dashboard
|
||||
case 'kC5mfynCi4':
|
||||
return {
|
||||
reportName: 'Drafts',
|
||||
params: {
|
||||
Type: null,
|
||||
$or: [
|
||||
{ Signers: null, SignedUrl: null },
|
||||
{ Signers: { $exists: true }, Placeholders: null },
|
||||
],
|
||||
CreatedBy: {
|
||||
__type: 'Pointer',
|
||||
className: '_User',
|
||||
objectId: currentUserId,
|
||||
},
|
||||
},
|
||||
keys: ['Name', 'Note', 'Folder.Name', 'URL', 'ExtUserPtr.Name', 'Signers.Name'],
|
||||
};
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user