salix/modules/order/back/methods/order/getTaxes.js

57 lines
1.5 KiB
JavaScript
Raw Normal View History

2019-02-27 11:03:54 +00:00
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
2018-08-07 14:04:42 +00:00
module.exports = Self => {
Self.remoteMethod('getTaxes', {
description: 'Gets the taxes of a given order',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'order id',
http: {source: 'path'}
}],
returns: {
type: 'object',
root: true
},
http: {
path: `/:id/getTaxes`,
verb: 'GET'
}
});
2021-12-15 14:29:22 +00:00
Self.getTaxes = async(orderFk, options) => {
const conn = Self.dataSource.connector;
const stmts = [];
2019-02-27 11:03:54 +00:00
let stmt;
2021-12-15 14:29:22 +00:00
const myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
2019-02-27 11:03:54 +00:00
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.order');
stmt = new ParameterizedSQL(`
CREATE TEMPORARY TABLE tmp.order
(INDEX (orderFk))
ENGINE = MEMORY
SELECT ? AS orderFk`, [orderFk]);
stmts.push(stmt);
2019-06-13 09:47:32 +00:00
stmts.push('CALL hedera.order_getTax()');
2019-02-27 11:03:54 +00:00
2021-12-15 14:29:22 +00:00
const orderTaxIndex = stmts.push('SELECT * FROM tmp.orderAmount') - 1;
2019-02-27 11:03:54 +00:00
stmts.push(`
DROP TEMPORARY TABLE
tmp.order,
tmp.orderTax`);
2021-12-15 14:29:22 +00:00
const sql = ParameterizedSQL.join(stmts, ';');
const result = await conn.executeStmt(sql, myOptions);
2018-08-07 14:04:42 +00:00
2019-02-27 11:03:54 +00:00
return result[orderTaxIndex];
2018-08-07 14:04:42 +00:00
};
};