From 81dc09999ff0b192f78dd38992e96f3165a59784 Mon Sep 17 00:00:00 2001 From: gerard Date: Tue, 24 Jul 2018 12:57:07 +0200 Subject: [PATCH] Tarea #406 order.volumen --- .../order/common/methods/order/getTotal.js | 2 +- .../common/methods/order/getTotalVolume.js | 27 +++++++++++++++++++ .../order/common/methods/order/getVolumes.js | 25 +++++++++++++++++ services/order/common/models/order.js | 3 ++- 4 files changed, 55 insertions(+), 2 deletions(-) create mode 100644 services/order/common/methods/order/getTotalVolume.js create mode 100644 services/order/common/methods/order/getVolumes.js diff --git a/services/order/common/methods/order/getTotal.js b/services/order/common/methods/order/getTotal.js index 22d034d99..bc2cf1471 100644 --- a/services/order/common/methods/order/getTotal.js +++ b/services/order/common/methods/order/getTotal.js @@ -22,7 +22,7 @@ module.exports = Self => { Self.getTotal = async orderFk => { let query = `SELECT hedera.orderGetTotal(?) total;`; let [total] = await Self.rawSql(query, [orderFk]); - console.log(total); + return total; }; }; diff --git a/services/order/common/methods/order/getTotalVolume.js b/services/order/common/methods/order/getTotalVolume.js new file mode 100644 index 000000000..93dbcbee8 --- /dev/null +++ b/services/order/common/methods/order/getTotalVolume.js @@ -0,0 +1,27 @@ +module.exports = Self => { + Self.remoteMethod('getTotalVolume', { + description: 'Gets the total volume for an order', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'ticket id', + http: {source: 'path'} + }], + returns: { + type: 'number', + root: true + }, + http: { + path: `/:id/getTotalVolume`, + verb: 'GET' + } + }); + + Self.getTotalVolume = async orderFk => { + let query = `SELECT vn.orderTotalVolume(?) totalVolume, vn.orderTotalVolumeBoxes(?) totalBoxes`; + let [res] = await Self.rawSql(query, [orderFk, orderFk]); + return res; + }; +}; diff --git a/services/order/common/methods/order/getVolumes.js b/services/order/common/methods/order/getVolumes.js new file mode 100644 index 000000000..f7583f425 --- /dev/null +++ b/services/order/common/methods/order/getVolumes.js @@ -0,0 +1,25 @@ +module.exports = Self => { + Self.remoteMethod('getVolume', { + description: 'Returns the volumes of a order', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'order id', + http: {source: 'path'} + }], + returns: { + arg: 'volumes' + }, + http: { + path: `/:id/getVolumes`, + verb: 'GET' + } + }); + + Self.getVolume = async orderFk => { + let [volume] = await Self.rawSql(`CALL vn.orderListVolume(?)`, [orderFk]); + return volume; + }; +}; diff --git a/services/order/common/models/order.js b/services/order/common/models/order.js index e81d93982..95ae568d6 100644 --- a/services/order/common/models/order.js +++ b/services/order/common/models/order.js @@ -1,6 +1,7 @@ module.exports = Self => { require('../methods/new')(Self); - //require('../methods/order/getTotalVolume')(Self); + require('../methods/order/getTotalVolume')(Self); + require('../methods/order/getVolumes')(Self); require('../methods/order/getTotal')(Self); require('../methods/order/itemFilter')(Self); };