1
1
import axios from 'axios' ;
2
+ import { customAPIurl } from '../../../../Utils.js' ;
2
3
3
4
export default async function createDocumentWithTemplate ( request , response ) {
4
5
const signers = request . body . signers ;
5
6
const folderId = request . body . folderId ;
6
7
const templateId = request . params . template_id ;
7
- const url = new URL ( process . env . SERVER_URL ) ;
8
- let protocol = url . origin ;
8
+ const protocol = customAPIurl ( ) ;
9
9
10
10
try {
11
11
const reqToken = request . headers [ 'x-api-token' ] ;
@@ -24,11 +24,14 @@ export default async function createDocumentWithTemplate(request, response) {
24
24
if ( templateRes ) {
25
25
const template = JSON . parse ( JSON . stringify ( templateRes ) ) ;
26
26
if ( template ?. Placeholders ?. length > 0 ) {
27
- let isValid = template ?. Placeholders ?. length <= signers ?. length ;
28
- let updateSigners = template ?. Placeholders ?. every ( y =>
29
- signers ?. some ( x => x . Role === y . Role )
30
- ) ;
31
-
27
+ const emptyplaceholder = template ?. Placeholders . filter ( x => ! x . signerObjId ) ;
28
+ const isValid =
29
+ signers . length >= emptyplaceholder . length &&
30
+ signers . length <= template ?. Placeholders ?. length ;
31
+ const placeholder =
32
+ signers . length > emptyplaceholder . length ? template . Placeholders : emptyplaceholder ;
33
+ const updateSigners = placeholder . every ( y => signers ?. some ( x => x . Role === y . Role ) ) ;
34
+ // console.log('isValid ', isValid);
32
35
if ( isValid && updateSigners ) {
33
36
const folderPtr = {
34
37
__type : 'Pointer' ,
@@ -68,7 +71,7 @@ export default async function createDocumentWithTemplate(request, response) {
68
71
const newObj = { ...obj , contactPtr : contactPtr } ;
69
72
contact . push ( newObj ) ;
70
73
} catch ( err ) {
71
- console . log ( 'err ' , err ) ;
74
+ // console.log('err ', err);
72
75
if ( err ?. response ?. data ?. objectId ) {
73
76
const contactPtr = {
74
77
__type : 'Pointer' ,
@@ -77,6 +80,8 @@ export default async function createDocumentWithTemplate(request, response) {
77
80
} ;
78
81
const newObj = { ...obj , contactPtr : contactPtr } ;
79
82
contact . push ( newObj ) ;
83
+ } else {
84
+ console . log ( 'err ' , err ) ;
80
85
}
81
86
}
82
87
}
0 commit comments