2018-07-04 12:41:01 +00:00
|
|
|
module.exports = Self => {
|
|
|
|
Self.remoteMethod('getSales', {
|
|
|
|
description: 'New filter',
|
|
|
|
accessType: 'READ',
|
|
|
|
accepts: [{
|
|
|
|
arg: 'ticketFk',
|
|
|
|
type: 'number',
|
|
|
|
required: true,
|
|
|
|
description: 'ticket id',
|
|
|
|
http: {source: 'path'}
|
|
|
|
}],
|
|
|
|
returns: {
|
|
|
|
type: ['Object'],
|
|
|
|
root: true
|
|
|
|
},
|
|
|
|
http: {
|
|
|
|
path: `/:ticketFk/getSales`,
|
|
|
|
verb: 'get'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
Self.getSales = async ticketFk => {
|
|
|
|
let query = `CALL vn.ticketGetVisibleAvailable(?)`;
|
|
|
|
let [lines] = await Self.rawSql(query, [ticketFk]);
|
|
|
|
let ids = [];
|
|
|
|
|
|
|
|
for (line of lines)
|
|
|
|
ids.push(line.itemFk);
|
|
|
|
|
|
|
|
let filter = {
|
2018-11-06 08:21:53 +00:00
|
|
|
fields: ['id', 'name', 'tag5', 'value5', 'tag6', 'value6', 'tag7', 'value7', 'tag8', 'value8', 'tag9', 'value9', 'tag10', 'value10'],
|
|
|
|
where: {id: {inq: ids}}
|
2018-07-04 12:41:01 +00:00
|
|
|
};
|
|
|
|
let items = await Self.app.models.Item.find(filter);
|
|
|
|
|
|
|
|
let map = {};
|
|
|
|
for (item of items)
|
|
|
|
map[item.id] = item;
|
|
|
|
|
|
|
|
for (line of lines)
|
2018-11-06 08:21:53 +00:00
|
|
|
line.tags = map[line.itemFk];
|
2018-07-04 12:41:01 +00:00
|
|
|
|
|
|
|
return lines;
|
|
|
|
};
|
|
|
|
};
|