From c115c7c7579b6a67ea0672173728fc4d3b3173fe Mon Sep 17 00:00:00 2001 From: prafull-opensignlabs Date: Sat, 3 Feb 2024 18:51:58 +0530 Subject: [PATCH] fix: createdocument & createtemplate api not working properly --- .../v1/routes/createDocumentwithCoordinate.js | 69 ++++++++++-------- .../v1/routes/createTemplatewithCoordinate.js | 71 +++++++++++-------- 2 files changed, 82 insertions(+), 58 deletions(-) diff --git a/apps/OpenSignServer/cloud/customRoute/v1/routes/createDocumentwithCoordinate.js b/apps/OpenSignServer/cloud/customRoute/v1/routes/createDocumentwithCoordinate.js index 8c1c4e68d..217ca5e2d 100644 --- a/apps/OpenSignServer/cloud/customRoute/v1/routes/createDocumentwithCoordinate.js +++ b/apps/OpenSignServer/cloud/customRoute/v1/routes/createDocumentwithCoordinate.js @@ -108,35 +108,48 @@ export default async function createDocumentwithCoordinate(request, response) { 'Signers', contact?.map(x => x.contactPtr) ); - let updatePlaceholders = contact.map(x => { + let updatePlaceholders = contact.map((signer, index) => { + const placeHolder = []; + + for (const widget of signer.widgets) { + const pageNumber = widget.page; + const page = placeHolder.find(page => page.pageNumber === pageNumber); + + const widgetData = { + xPosition: widget.x, + yPosition: widget.y, + isStamp: widget.type === 'stamp', + key: Math.floor(Math.random() * 10000), + isDrag: false, + firstXPos: widget.x, + firstYPos: widget.y, + yBottom: 0, + scale: 1, + isMobile: false, + zIndex: 1, + type: widget.type, + widgetValue: '', + Width: widget.w, + Height: widget.h, + }; + + if (page) { + page.pos.push(widgetData); + } else { + placeHolder.push({ + pageNumber, + pos: [widgetData], + }); + } + } + return { - signerObjId: x?.contactPtr?.objectId, - signerPtr: x?.contactPtr, - Role: x.role, - Id: randomId(), - blockColor: color[x?.index], - placeHolder: x.widgets.map((widget, i) => ({ - pageNumber: widget.page, - pos: [ - { - xPosition: widget.x, - yPosition: widget.y, - isStamp: widget.type === 'stamp' || widget.type === 'image' ? true : false, - key: randomId(), - isDrag: false, - firstXPos: widget.x, - firstYPos: widget.y, - yBottom: 0, - scale: 1, - isMobile: false, - zIndex: i + 1, - type: widget.type, - widgetValue: '', - Width: widget.w, - Height: widget.h, - }, - ], - })), + signerObjId: signer?.contactPtr?.objectId, + signerPtr: signer?.contactPtr, + Role: signer.role, + Id: 3000 + index * 1000, + blockColor: color[signer?.index], + placeHolder, }; }); object.set('Placeholders', updatePlaceholders); diff --git a/apps/OpenSignServer/cloud/customRoute/v1/routes/createTemplatewithCoordinate.js b/apps/OpenSignServer/cloud/customRoute/v1/routes/createTemplatewithCoordinate.js index 8e6c619e9..4c753a6d0 100644 --- a/apps/OpenSignServer/cloud/customRoute/v1/routes/createTemplatewithCoordinate.js +++ b/apps/OpenSignServer/cloud/customRoute/v1/routes/createTemplatewithCoordinate.js @@ -113,39 +113,50 @@ export default async function createTemplatewithCoordinate(request, response) { updatedSigners?.map(x => x.contactPtr) ); } - let updatePlaceholders = contact.map(x => { + let updatePlaceholders = contact.map((signer, index) => { + const placeHolder = []; + + for (const widget of signer.widgets) { + const pageNumber = widget.page; + const page = placeHolder.find(page => page.pageNumber === pageNumber); + + const widgetData = { + xPosition: widget.x, + yPosition: widget.y, + isStamp: widget.type === 'stamp', + key: Math.floor(Math.random() * 10000), + isDrag: false, + firstXPos: widget.x, + firstYPos: widget.y, + yBottom: 0, + scale: 1, + isMobile: false, + zIndex: 1, + type: widget.type, + widgetValue: '', + Width: widget.w, + Height: widget.h, + }; + + if (page) { + page.pos.push(widgetData); + } else { + placeHolder.push({ + pageNumber, + pos: [widgetData], + }); + } + } + return { - signerObjId: x?.contactPtr?.objectId || '', - signerPtr: x?.contactPtr || {}, - Role: x.role, - Id: randomId(), - blockColor: color[x?.index], - placeHolder: x.widgets.map((widget, i) => ({ - pageNumber: widget.page, - pos: [ - { - xPosition: widget.x, - yPosition: widget.y, - isStamp: widget.type === 'stamp' || widget.type === 'image' ? true : false, - key: randomId(), - isDrag: false, - firstXPos: widget.x, - firstYPos: widget.y, - yBottom: 0, - scale: 1, - isMobile: false, - zIndex: i + 1, - type: widget.type, - widgetValue: '', - Width: widget.w, - Height: widget.h, - }, - ], - })), + signerObjId: signer?.contactPtr?.objectId, + signerPtr: signer?.contactPtr, + Role: signer.role, + Id: 3000 + index * 1000, + blockColor: color[signer?.index], + placeHolder, }; }); - // console.log('updatePLacholders', updatePlaceholders); - object.set('Placeholders', updatePlaceholders); } if (folderId) {