From b972353bb4954a5b85b8eb297910528be8e7198d Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Tue, 21 Jul 2020 11:11:09 +0200 Subject: [PATCH] create method getComponentSum --- .../back/methods/ticket/getComponentsSum.js | 32 +++++++++++++++++++ modules/ticket/back/models/ticket.js | 1 + modules/ticket/front/component/index.html | 4 +-- modules/ticket/front/component/index.js | 6 +++- 4 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 modules/ticket/back/methods/ticket/getComponentsSum.js diff --git a/modules/ticket/back/methods/ticket/getComponentsSum.js b/modules/ticket/back/methods/ticket/getComponentsSum.js new file mode 100644 index 000000000..d254b3af3 --- /dev/null +++ b/modules/ticket/back/methods/ticket/getComponentsSum.js @@ -0,0 +1,32 @@ +module.exports = Self => { + Self.remoteMethod('getComponentsSum', { + description: 'Returns the list of component and their sum from a ticket', + accessType: 'READ', + accepts: { + arg: 'id', + type: 'number', + required: true, + description: 'ticket id', + http: {source: 'path'} + }, + returns: { + type: 'Number', + root: true + }, + http: { + path: `/:id/getComponentsSum`, + verb: 'GET' + } + }); + + Self.getComponentsSum = async id => { + const models = Self.app.models; + let sales = await models.Sale.find({where: {ticketFk: id}}); + let salesComponents; + for (let sale of sales) { + salesComponents = await models.SaleComponent.find({saleFk: sale.id}); + console.log('salesComponents', salesComponents); + } + return true; + }; +}; diff --git a/modules/ticket/back/models/ticket.js b/modules/ticket/back/models/ticket.js index 3afc6301c..d6ef50fb3 100644 --- a/modules/ticket/back/models/ticket.js +++ b/modules/ticket/back/models/ticket.js @@ -31,6 +31,7 @@ module.exports = Self => { require('../methods/ticket/sendSms')(Self); require('../methods/ticket/isLocked')(Self); require('../methods/ticket/freightPorts')(Self); + require('../methods/ticket/getComponentsSum')(Self); Self.observe('before save', async function(ctx) { if (ctx.isNewInstance) return; diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 6706df1af..4cfbd3ce6 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -62,7 +62,7 @@ -
+
Total
Base to commission {{$ctrl.base() | currency: 'EUR':3}}
@@ -78,7 +78,7 @@
Theorical ports
Price {{$ctrl.theoricalPorts | currency: 'EUR': 2}}
-
+
this.theoricalPorts = res.data); + } - console.log('this.THasdasdasdeoricalPorts', this.theoricalPorts); + getComponentsSum() { + this.$http.get(`Tickets/${this.ticket.id}/getComponentsSum`) + .then(res => this.componentsList = res.data); } }