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