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