parent
f34ab37afb
commit
ee2b03cabf
|
@ -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
|
||||
);
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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');
|
||||
|
|
Loading…
Reference in New Issue