salix/back/methods/docuware/checkFile.js

95 lines
2.5 KiB
JavaScript
Raw Normal View History

const axios = require('axios');
2022-02-16 13:57:47 +00:00
module.exports = Self => {
Self.remoteMethod('checkFile', {
description: 'Check if exist docuware file',
2022-02-16 13:57:47 +00:00
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'number',
description: 'The id',
2022-02-16 13:57:47 +00:00
http: {source: 'path'}
},
{
arg: 'fileCabinet',
type: 'string',
required: true,
description: 'The fileCabinet name'
},
{
arg: 'filter',
type: 'object',
description: 'The filter'
},
{
arg: 'signed',
type: 'boolean',
description: 'If pdf is necessary to be signed'
},
2022-02-16 13:57:47 +00:00
],
returns: {
type: 'object',
2022-02-16 13:57:47 +00:00
root: true
},
http: {
path: `/:id/checkFile`,
verb: 'POST'
2022-02-16 13:57:47 +00:00
}
});
Self.checkFile = async function(id, fileCabinet, filter, signed) {
2022-02-16 13:57:47 +00:00
const models = Self.app.models;
const action = 'find';
2022-02-16 13:57:47 +00:00
const docuwareInfo = await models.Docuware.findOne({
where: {
2022-02-22 14:23:23 +00:00
code: fileCabinet,
action: action
2022-02-16 13:57:47 +00:00
}
});
2023-05-31 09:32:37 +00:00
if (!filter) {
filter = {
condition: [
{
DBName: docuwareInfo.findById,
Value: [id]
}
],
sortOrder: [
{
Field: 'FILENAME',
Direction: 'Desc'
}
]
};
}
if (signed) {
filter.condition.push({
DBName: 'ESTADO',
Value: ['Firmado']
});
}
2022-02-16 13:57:47 +00:00
try {
const options = await Self.getOptions();
const fileCabinetId = await Self.getFileCabinet(fileCabinet);
const dialogId = await Self.getDialog(fileCabinet, action, fileCabinetId);
const response = await axios.post(
`${options.url}/FileCabinets/${fileCabinetId}/Query/DialogExpression?dialogId=${dialogId}`,
filter,
options.headers
);
const [documents] = response.data.Items;
if (!documents) return false;
2023-01-09 14:11:53 +00:00
return {id: documents.Id};
2022-02-16 13:57:47 +00:00
} catch (error) {
return false;
}
};
};