feat(salix): refs #5926 #5926 update docuware.core

This commit is contained in:
Javier Segarra 2024-06-07 01:59:50 +02:00
parent f34ab37afb
commit ee2b03cabf
3 changed files with 18 additions and 6 deletions

View File

@ -25,16 +25,17 @@ module.exports = Self => {
* *
* @param {string} value - The document value * @param {string} value - The document value
* @param {Object} configTemplate - The config as template upload * @param {Object} configTemplate - The config as template upload
* @param {string} fileName - The document fileName with extension
* @param {object} options - The options * @param {object} options - The options
* @return {object} - The options with headers * @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 FormData = require('form-data');
const data = new FormData(); const data = new FormData();
const docuwareOptions = options ?? await Self.getOptions(); const docuwareOptions = options ?? await Self.getOptions();
const templateJson = Self.buildTemplateJSON(configTemplate); const templateJson = Self.buildTemplateJSON(configTemplate);
data.append('document', JSON.stringify(templateJson), 'schema.json'); data.append('document', JSON.stringify(templateJson), 'schema.json');
data.append('file[]', value, 'pda.pdf'); data.append('file[]', value, fileName);
const uploadOptions = { const uploadOptions = {
headers: { headers: {
'Content-Type': 'multipart/form-data', 'Content-Type': 'multipart/form-data',
@ -77,6 +78,17 @@ module.exports = Self => {
Self.getDocuware = async filter => { Self.getDocuware = async filter => {
return await Self.app.models.Docuware.findOne(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 * Returns the dialog id
@ -97,7 +109,7 @@ module.exports = Self => {
const options = await Self.getOptions(); 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 dialogs = response.data.Dialog;
const dialogId = dialogs.find(dialogs => dialogs.DisplayName === docuwareInfo.dialogName).Id; 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 dialogId = await Self.getDialog(code, 'find', fileCabinetId);
const data = await axios.post( const data = await axios.post(
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`, `${Self.baseURL(options, fileCabinetId)}/Query/DialogExpression?dialogId=${dialogId}`,
filter, filter,
options.headers options.headers
); );

View File

@ -58,7 +58,7 @@ module.exports = Self => {
const fileName = `filename="${id}.pdf"`; const fileName = `filename="${id}.pdf"`;
const contentType = 'application/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); const stream = await axios.get(downloadUri, options.headers);

View File

@ -58,7 +58,7 @@ module.exports = Self => {
const fileCabinetId = await Self.getFileCabinet(fileCabinet); const fileCabinetId = await Self.getFileCabinet(fileCabinet);
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId); 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)) // if (!isProduction(false))
// throw new UserError('Action not allowed on the test environment'); // throw new UserError('Action not allowed on the test environment');