salix/back/methods/docuware/checkFile.js

87 lines
2.4 KiB
JavaScript
Raw Normal View History

const axios = require('axios');
2022-02-16 13:57:47 +00:00
module.exports = Self => {
Self.remoteMethodCtx('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: 'signed',
type: 'boolean',
required: true,
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(ctx, id, fileCabinet, 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
}
});
2022-02-28 12:27:03 +00:00
const searchFilter = {
condition: [
{
DBName: docuwareInfo.findById,
Value: [id]
}
],
sortOrder: [
{
Field: 'FILENAME',
Direction: 'Desc'
}
]
2022-02-16 13:57:47 +00:00
};
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}`,
searchFilter,
options.headers
);
const [documents] = response.data.Items;
if (!documents) return false;
2023-01-09 14:11:53 +00:00
const state = documents.Fields.find(field => field.FieldName == 'ESTADO');
if (signed && state.Item != 'Firmado') 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;
}
};
};