salix/services/loopback/common/methods/sale/priceDifference.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

2018-04-10 05:48:04 +00:00
module.exports = Self => {
Self.remoteMethod('priceDifference', {
description: 'Returns a sale price difference',
2018-04-10 05:48:04 +00:00
accessType: 'READ',
accepts: [{
arg: 'ticketFk',
type: 'number',
required: true,
description: 'ticket id',
http: {source: 'path'}
}],
returns: {
type: ['Object'],
root: true
},
http: {
path: `/:ticketFk/priceDifference`,
2018-04-10 05:48:04 +00:00
verb: 'GET'
}
});
Self.priceDifference = async ticketFk => {
2018-04-10 05:48:04 +00:00
let filter = {
where: {
ticketFk: ticketFk
},
order: 'concept ASC',
include: [{
relation: 'item',
scope: {
include: {
relation: 'tags',
2018-04-10 05:48:04 +00:00
scope: {
fields: ['tagFk', 'value'],
include: {
relation: 'tag',
scope: {
fields: ['name']
}
},
limit: 6
}
},
fields: ['itemFk', 'name']
}
}]
};
return await Self.find(filter);
};
};