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