salix/back/methods/docuware/checkFile.js

83 lines
2.1 KiB
JavaScript
Raw Permalink Normal View History

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 [response] = await Self.get(fileCabinet, filter);
if (!response) return false;
2023-01-09 14:11:53 +00:00
return {id: response['Document ID']};
2022-02-16 13:57:47 +00:00
} catch (error) {
return false;
}
};
};