2018-04-10 05:48:04 +00:00
|
|
|
module.exports = Self => {
|
2018-05-04 09:46:03 +00:00
|
|
|
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: {
|
2018-05-04 09:46:03 +00:00
|
|
|
path: `/:ticketFk/priceDifference`,
|
2018-04-10 05:48:04 +00:00
|
|
|
verb: 'GET'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2018-05-04 09:46:03 +00:00
|
|
|
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: {
|
2018-04-26 14:41:08 +00:00
|
|
|
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);
|
|
|
|
};
|
|
|
|
};
|