salix/modules/ticket/back/methods/sale-tracking/listSaleTracking.js

54 lines
1.4 KiB
JavaScript
Raw Permalink Normal View History

const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
module.exports = Self => {
Self.remoteMethod('listSaleTracking', {
description: 'Returns all ticket sale trackings',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'object',
description: 'Filter defining where and paginated data'
}],
returns: {
type: ['object'],
root: true
},
http: {
path: `/listSaleTracking`,
verb: 'get'
}
});
Self.listSaleTracking = async(filter, options) => {
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const stmt = new ParameterizedSQL(`
2020-10-06 08:15:27 +00:00
SELECT
st.id,
s.ticketFk,
s.quantity,
s.concept,
s.itemFk,
st.originalQuantity,
st.created,
st.workerFk,
u.name,
2020-10-06 08:15:27 +00:00
ste.name AS state
FROM saleTracking st
JOIN sale s ON s.id = st.saleFk
JOIN worker w ON w.id = st.workerFk
2023-08-22 08:45:41 +00:00
JOIN account.user u ON u.id = w.id
2020-10-06 08:15:27 +00:00
JOIN state ste ON ste.id = st.stateFk`);
stmt.merge(Self.makeSuffix(filter));
const trackings = await Self.rawStmt(stmt, myOptions);
return trackings;
};
};