salix/modules/ticket/back/methods/ticket/docuwareDownload.js

64 lines
1.6 KiB
JavaScript

module.exports = Self => {
Self.remoteMethod('docuwareDownload', {
description: 'Download a ticket delivery note document',
accessType: 'READ',
accepts: [
{
arg: 'id',
type: 'Number',
description: 'The document id',
http: {source: 'path'}
}
],
returns: [
{
arg: 'body',
type: 'file',
root: true
}, {
arg: 'Content-Type',
type: 'String',
http: {target: 'header'}
}, {
arg: 'Content-Disposition',
type: 'String',
http: {target: 'header'}
}
],
http: {
path: `/:id/docuwareDownload`,
verb: 'GET'
}
});
Self.docuwareDownload = async id => {
const models = Self.app.models;
const docuwareInfo = await models.Docuware.findOne({
where: {
code: 'deliveryNote',
action: 'find'
}
});
const filter = {
condition: [
{
DBName: docuwareInfo.findById,
Value: [id]
},
{
DBName: 'ESTADO',
Value: ['Firmado']
}
],
sortOrder: [
{
Field: 'FILENAME',
Direction: 'Desc'
}
]
};
return models.Docuware.download(id, 'deliveryNote', filter);
};
};