From ee2b03cabf94bb9498cd7967a3f7ae6d4c8998c3 Mon Sep 17 00:00:00 2001 From: Javier Segarra Date: Fri, 7 Jun 2024 01:59:50 +0200 Subject: [PATCH] feat(salix): refs #5926 #5926 update docuware.core --- back/methods/docuware/core.js | 20 ++++++++++++++++---- back/methods/docuware/download.js | 2 +- back/methods/docuware/upload.js | 2 +- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/back/methods/docuware/core.js b/back/methods/docuware/core.js index d3e8373a9..7db5836f0 100644 --- a/back/methods/docuware/core.js +++ b/back/methods/docuware/core.js @@ -25,16 +25,17 @@ module.exports = Self => { * * @param {string} value - The document value * @param {Object} configTemplate - The config as template upload + * @param {string} fileName - The document fileName with extension * @param {object} options - The options * @return {object} - The options with headers */ - Self.uploadOptions = async(value, configTemplate, options) => { + Self.uploadOptions = async(value, configTemplate, fileName = '', options) => { const FormData = require('form-data'); const data = new FormData(); const docuwareOptions = options ?? await Self.getOptions(); const templateJson = Self.buildTemplateJSON(configTemplate); data.append('document', JSON.stringify(templateJson), 'schema.json'); - data.append('file[]', value, 'pda.pdf'); + data.append('file[]', value, fileName); const uploadOptions = { headers: { 'Content-Type': 'multipart/form-data', @@ -77,6 +78,17 @@ module.exports = Self => { Self.getDocuware = async filter => { return await Self.app.models.Docuware.findOne(filter); }; + /** + * Returns the base url + * + * @param {object} options - The docuware options + * @param {string} fileCabinetId - The fileCabinetId to use in findOne method + * @param {string} model - The model to use in findOne method + * @return {string} - The doware record + */ + Self.baseURL = (options, fileCabinetId, model) => { + return `${options.url}/FileCabinets/${fileCabinetId}/${model}`; + }; /** * Returns the dialog id @@ -97,7 +109,7 @@ module.exports = Self => { const options = await Self.getOptions(); - const response = await axios.get(`${options.url}/FileCabinets/${fileCabinetId}/dialogs`, options.headers); + const response = await axios.get(Self.baseURL(options, fileCabinetId, 'dialog'), options.headers); const dialogs = response.data.Dialog; const dialogId = dialogs.find(dialogs => dialogs.DisplayName === docuwareInfo.dialogName).Id; @@ -142,7 +154,7 @@ module.exports = Self => { const dialogId = await Self.getDialog(code, 'find', fileCabinetId); const data = await axios.post( - `${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, + `${Self.baseURL(options, fileCabinetId)}/Query/DialogExpression?dialogId=${dialogId}`, filter, options.headers ); diff --git a/back/methods/docuware/download.js b/back/methods/docuware/download.js index eb575236d..83f3ba919 100644 --- a/back/methods/docuware/download.js +++ b/back/methods/docuware/download.js @@ -58,7 +58,7 @@ module.exports = Self => { const fileName = `filename="${id}.pdf"`; const contentType = 'application/pdf'; - const downloadUri = `${options.url}/FileCabinets/${fileCabinetId}/Documents/${docuwareFile.id}/FileDownload?targetFileType=Auto&keepAnnotations=false`; + const downloadUri = `${Self.baseURL(options, fileCabinetId)}Documents/${docuwareFile.id}/FileDownload?targetFileType=Auto&keepAnnotations=false`; const stream = await axios.get(downloadUri, options.headers); diff --git a/back/methods/docuware/upload.js b/back/methods/docuware/upload.js index 5be0120a7..cddd8aff1 100644 --- a/back/methods/docuware/upload.js +++ b/back/methods/docuware/upload.js @@ -58,7 +58,7 @@ module.exports = Self => { const fileCabinetId = await Self.getFileCabinet(fileCabinet); const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId); - const uri = `${docuwareOptions.url}/FileCabinets/${fileCabinetId}/Documents`; + const uri = Self.baseURL(docuwareOptions, fileCabinetId, 'Documents'); // if (!isProduction(false)) // throw new UserError('Action not allowed on the test environment');