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');