mirror of
https://github.com/OpenSignLabs/OpenSign.git
synced 2026-08-17 21:25:54 +02:00
fix: createdocument, createtemplate and createdocumentwithtemplate APIs not working
This commit is contained in:
@@ -0,0 +1,4 @@
|
||||
export function customAPIurl() {
|
||||
const url = new URL(process.env.SERVER_URL);
|
||||
return url.pathname === '/api/app' ? url.origin + '/api' : url.origin;
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
import axios from 'axios';
|
||||
import { customAPIurl } from '../../../../Utils.js';
|
||||
|
||||
export default async function createDocumentWithTemplate(request, response) {
|
||||
const signers = request.body.signers;
|
||||
const folderId = request.body.folderId;
|
||||
const templateId = request.params.template_id;
|
||||
const url = new URL(process.env.SERVER_URL);
|
||||
let protocol = url.origin;
|
||||
const protocol = customAPIurl();
|
||||
|
||||
try {
|
||||
const reqToken = request.headers['x-api-token'];
|
||||
@@ -24,11 +24,14 @@ export default async function createDocumentWithTemplate(request, response) {
|
||||
if (templateRes) {
|
||||
const template = JSON.parse(JSON.stringify(templateRes));
|
||||
if (template?.Placeholders?.length > 0) {
|
||||
let isValid = template?.Placeholders?.length <= signers?.length;
|
||||
let updateSigners = template?.Placeholders?.every(y =>
|
||||
signers?.some(x => x.Role === y.Role)
|
||||
);
|
||||
|
||||
const emptyplaceholder = template?.Placeholders.filter(x => !x.signerObjId);
|
||||
const isValid =
|
||||
signers.length >= emptyplaceholder.length &&
|
||||
signers.length <= template?.Placeholders?.length;
|
||||
const placeholder =
|
||||
signers.length > emptyplaceholder.length ? template.Placeholders : emptyplaceholder;
|
||||
const updateSigners = placeholder.every(y => signers?.some(x => x.Role === y.Role));
|
||||
// console.log('isValid ', isValid);
|
||||
if (isValid && updateSigners) {
|
||||
const folderPtr = {
|
||||
__type: 'Pointer',
|
||||
@@ -68,7 +71,7 @@ export default async function createDocumentWithTemplate(request, response) {
|
||||
const newObj = { ...obj, contactPtr: contactPtr };
|
||||
contact.push(newObj);
|
||||
} catch (err) {
|
||||
console.log('err ', err);
|
||||
// console.log('err ', err);
|
||||
if (err?.response?.data?.objectId) {
|
||||
const contactPtr = {
|
||||
__type: 'Pointer',
|
||||
@@ -77,6 +80,8 @@ export default async function createDocumentWithTemplate(request, response) {
|
||||
};
|
||||
const newObj = { ...obj, contactPtr: contactPtr };
|
||||
contact.push(newObj);
|
||||
} else {
|
||||
console.log('err ', err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import axios from 'axios';
|
||||
import { customAPIurl } from '../../../../Utils.js';
|
||||
|
||||
// const randomId = () => Math.floor(1000 + Math.random() * 9000);
|
||||
export default async function createDocument(request, response) {
|
||||
@@ -10,8 +11,7 @@ export default async function createDocument(request, response) {
|
||||
const base64File = request.body.file;
|
||||
const fileData = request.files?.[0] ? request.files[0].buffer : null;
|
||||
// console.log('fileData ', fileData);
|
||||
const url = new URL(process.env.SERVER_URL);
|
||||
let protocol = url.origin;
|
||||
const protocol = customAPIurl();
|
||||
|
||||
try {
|
||||
const reqToken = request.headers['x-api-token'];
|
||||
@@ -128,4 +128,4 @@ export default async function createDocument(request, response) {
|
||||
console.log('err ', err);
|
||||
return response.status(400).json({ error: 'Something went wrong!' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
import { customAPIurl } from '../../../../Utils.js';
|
||||
|
||||
const randomId = () => Math.floor(1000 + Math.random() * 9000);
|
||||
export default async function createTemplate(request, response) {
|
||||
const name = request.body?.title;
|
||||
@@ -7,8 +9,7 @@ export default async function createTemplate(request, response) {
|
||||
const folderId = request.body?.folderId;
|
||||
const base64File = request.body.file;
|
||||
const fileData = request.files?.[0] ? request.files[0].buffer : null;
|
||||
const url = new URL(process.env.SERVER_URL);
|
||||
let protocol = url.origin;
|
||||
const protocol = customAPIurl();
|
||||
|
||||
try {
|
||||
const reqToken = request.headers['x-api-token'];
|
||||
@@ -114,4 +115,4 @@ export default async function createTemplate(request, response) {
|
||||
console.log('err ', err);
|
||||
return response.status(400).json({ error: 'Something went wrong, please try again later!' });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user