Skip to content

Commit e7280bf

Browse files
authored
Merge pull request #374 from OpenSignLabs/api-v1-beta
2 parents 4edcf80 + 9692f57 commit e7280bf

File tree

3 files changed

+92
-73
lines changed

3 files changed

+92
-73
lines changed

apps/OpenSignServer/cloud/customRoute/v1/apiV1.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,10 @@ app.delete('/contact/:contact_id', deleteContact);
5050
app.get('/contactlist', getContactList);
5151

5252
// create Document
53-
app.post('/createdocumentwithbinary', upload.array('file', 1), createDocument);
53+
app.post('/createdocumentwithbinary', upload.array('file', 1), createDocumentwithCoordinate);
5454

5555
// create Document with co-ordinate
56-
app.post('/createdocument', upload.array('file', 1), createDocumentwithCoordinate);
56+
app.post('/createdocument', createDocumentwithCoordinate);
5757

5858
// create Document with base64 without placeholder
5959
app.post('/draftdocument', createDocument);
@@ -74,13 +74,13 @@ app.delete('/document/:document_id', deleteDocument);
7474
app.get('/documentlist/:doctype', getDocumentList);
7575

7676
// create Template with co-ordinate
77-
app.post('/createtemplate', upload.array('file', 1), createTemplatewithCoordinate);
77+
app.post('/createtemplate', createTemplatewithCoordinate);
7878

7979
// create Template
8080
app.post('/drafttemplate', createTemplate);
8181

8282
// create Template with binary
83-
app.post('/createtemplatewithbinary', upload.array('file', 1), createTemplate);
83+
app.post('/createtemplatewithbinary', upload.array('file', 1), createTemplatewithCoordinate);
8484

8585
// get template on the basis of id
8686
app.get('/template/:template_id', getTemplate);

apps/OpenSignServer/cloud/customRoute/v1/routes/createDocumentwithCoordinate.js

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -108,35 +108,48 @@ export default async function createDocumentwithCoordinate(request, response) {
108108
'Signers',
109109
contact?.map(x => x.contactPtr)
110110
);
111-
let updatePlaceholders = contact.map(x => {
111+
let updatePlaceholders = contact.map((signer, index) => {
112+
const placeHolder = [];
113+
114+
for (const widget of signer.widgets) {
115+
const pageNumber = widget.page;
116+
const page = placeHolder.find(page => page.pageNumber === pageNumber);
117+
118+
const widgetData = {
119+
xPosition: widget.x,
120+
yPosition: widget.y,
121+
isStamp: widget.type === 'stamp',
122+
key: randomId(),
123+
isDrag: false,
124+
firstXPos: widget.x,
125+
firstYPos: widget.y,
126+
yBottom: 0,
127+
scale: 1,
128+
isMobile: false,
129+
zIndex: 1,
130+
type: widget.type,
131+
widgetValue: '',
132+
Width: widget.w,
133+
Height: widget.h,
134+
};
135+
136+
if (page) {
137+
page.pos.push(widgetData);
138+
} else {
139+
placeHolder.push({
140+
pageNumber,
141+
pos: [widgetData],
142+
});
143+
}
144+
}
145+
112146
return {
113-
signerObjId: x?.contactPtr?.objectId,
114-
signerPtr: x?.contactPtr,
115-
Role: x.role,
147+
signerObjId: signer?.contactPtr?.objectId,
148+
signerPtr: signer?.contactPtr,
149+
Role: signer.role,
116150
Id: randomId(),
117-
blockColor: color[x?.index],
118-
placeHolder: x.widgets.map((widget, i) => ({
119-
pageNumber: widget.page,
120-
pos: [
121-
{
122-
xPosition: widget.x,
123-
yPosition: widget.y,
124-
isStamp: widget.type === 'stamp' || widget.type === 'image' ? true : false,
125-
key: randomId(),
126-
isDrag: false,
127-
firstXPos: widget.x,
128-
firstYPos: widget.y,
129-
yBottom: 0,
130-
scale: 1,
131-
isMobile: false,
132-
zIndex: i + 1,
133-
type: widget.type,
134-
widgetValue: '',
135-
Width: widget.w,
136-
Height: widget.h,
137-
},
138-
],
139-
})),
151+
blockColor: color[signer?.index],
152+
placeHolder,
140153
};
141154
});
142155
object.set('Placeholders', updatePlaceholders);
@@ -220,19 +233,14 @@ export default async function createDocumentwithCoordinate(request, response) {
220233
}
221234

222235
if (sendMail.data.result.status === 'success') {
223-
const user = contact.find(x => x.email === parseExtUser.Email);
224-
if (user && user.email) {
225-
return response.json({
226-
objectId: res.id,
227-
url: `${baseUrl.origin}/loadmf/signmicroapp/login/${res.id}/${user.email}/${user.contactPtr.objectId}/${serverParams}`,
228-
message: 'Document sent successfully!',
229-
});
230-
} else {
231-
return response.json({
232-
objectId: res.id,
233-
message: 'Document sent successfully!',
234-
});
235-
}
236+
return response.json({
237+
objectId: res.id,
238+
signurl: contact.map(x => ({
239+
email: x.email,
240+
url: `${baseUrl.origin}/loadmf/signmicroapp/login/${res.id}/${x.email}/${x.contactPtr.objectId}/${serverParams}`,
241+
})),
242+
message: 'Document sent successfully!',
243+
});
236244
}
237245
} else {
238246
return response.status(400).json({ error: 'Please provide signers!' });

apps/OpenSignServer/cloud/customRoute/v1/routes/createTemplatewithCoordinate.js

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -113,39 +113,50 @@ export default async function createTemplatewithCoordinate(request, response) {
113113
updatedSigners?.map(x => x.contactPtr)
114114
);
115115
}
116-
let updatePlaceholders = contact.map(x => {
116+
let updatePlaceholders = contact.map((signer, index) => {
117+
const placeHolder = [];
118+
119+
for (const widget of signer.widgets) {
120+
const pageNumber = widget.page;
121+
const page = placeHolder.find(page => page.pageNumber === pageNumber);
122+
123+
const widgetData = {
124+
xPosition: widget.x,
125+
yPosition: widget.y,
126+
isStamp: widget.type === 'stamp',
127+
key: randomId(),
128+
isDrag: false,
129+
firstXPos: widget.x,
130+
firstYPos: widget.y,
131+
yBottom: 0,
132+
scale: 1,
133+
isMobile: false,
134+
zIndex: 1,
135+
type: widget.type,
136+
widgetValue: '',
137+
Width: widget.w,
138+
Height: widget.h,
139+
};
140+
141+
if (page) {
142+
page.pos.push(widgetData);
143+
} else {
144+
placeHolder.push({
145+
pageNumber,
146+
pos: [widgetData],
147+
});
148+
}
149+
}
150+
117151
return {
118-
signerObjId: x?.contactPtr?.objectId || '',
119-
signerPtr: x?.contactPtr || {},
120-
Role: x.role,
152+
signerObjId: signer?.contactPtr?.objectId,
153+
signerPtr: signer?.contactPtr,
154+
Role: signer.role,
121155
Id: randomId(),
122-
blockColor: color[x?.index],
123-
placeHolder: x.widgets.map((widget, i) => ({
124-
pageNumber: widget.page,
125-
pos: [
126-
{
127-
xPosition: widget.x,
128-
yPosition: widget.y,
129-
isStamp: widget.type === 'stamp' || widget.type === 'image' ? true : false,
130-
key: randomId(),
131-
isDrag: false,
132-
firstXPos: widget.x,
133-
firstYPos: widget.y,
134-
yBottom: 0,
135-
scale: 1,
136-
isMobile: false,
137-
zIndex: i + 1,
138-
type: widget.type,
139-
widgetValue: '',
140-
Width: widget.w,
141-
Height: widget.h,
142-
},
143-
],
144-
})),
156+
blockColor: color[signer?.index],
157+
placeHolder,
145158
};
146159
});
147-
// console.log('updatePLacholders', updatePlaceholders);
148-
149160
object.set('Placeholders', updatePlaceholders);
150161
}
151162
if (folderId) {

0 commit comments

Comments
 (0)