53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
|
module.exports = Self => {
|
||
|
Self.remoteMethodCtx('getChanges', {
|
||
|
description: 'Get item id and quantity changes on the sales of a ticket',
|
||
|
accessType: 'WRITE',
|
||
|
accepts: [
|
||
|
{
|
||
|
arg: 'ticketId',
|
||
|
description: 'the ticket id',
|
||
|
type: 'number',
|
||
|
required: true,
|
||
|
http: {source: 'body'}
|
||
|
}
|
||
|
],
|
||
|
returns: {
|
||
|
type: 'object',
|
||
|
root: true
|
||
|
},
|
||
|
http: {
|
||
|
path: `/:id/getChanges`,
|
||
|
verb: 'POST'
|
||
|
}
|
||
|
});
|
||
|
|
||
|
Self.getChanges = async(ctx, ticketId, options) => {
|
||
|
const models = Self.app.models;
|
||
|
const myOptions = {};
|
||
|
let tx;
|
||
|
|
||
|
if (typeof options == 'object')
|
||
|
Object.assign(myOptions, options);
|
||
|
|
||
|
if (!myOptions.transaction) {
|
||
|
tx = await Self.beginTransaction({});
|
||
|
myOptions.transaction = tx;
|
||
|
}
|
||
|
|
||
|
try {
|
||
|
const ticketLogs = await models.TicketLog.find({where: {originFk: ticketId}}, myOptions);
|
||
|
|
||
|
for (const ticketLog of ticketLogs) {
|
||
|
if (ticketLog)
|
||
|
}
|
||
|
|
||
|
if (tx) await tx.commit();
|
||
|
|
||
|
return state;
|
||
|
} catch (e) {
|
||
|
if (tx) await tx.rollback();
|
||
|
throw e;
|
||
|
}
|
||
|
};
|
||
|
};
|