From e9d3b14da74caa22a64f949cb1f0a75bc4f34a60 Mon Sep 17 00:00:00 2001 From: Bernat Exposito Domenech Date: Fri, 27 Dec 2019 08:01:53 +0100 Subject: [PATCH] refactor models component and componentType --- .../back/methods/sale/specs/updatePrice.spec.js | 4 ++-- modules/ticket/back/methods/sale/updatePrice.js | 2 +- .../methods/ticket/specs/componentUpdate.spec.js | 2 +- .../back/methods/ticket/specs/updateDiscount.spec.js | 2 +- modules/ticket/back/methods/ticket/updateDiscount.js | 2 +- modules/ticket/back/model-config.json | 4 ++-- ...{component-type-rate.json => component-type.json} | 2 +- .../models/{component-rate.json => component.json} | 4 ++-- modules/ticket/back/models/sale-component.json | 4 ++-- modules/ticket/front/component/index.html | 10 +++++----- modules/ticket/front/component/index.js | 8 ++++---- modules/ticket/front/component/index.spec.js | 12 ++++++------ 12 files changed, 28 insertions(+), 28 deletions(-) rename modules/ticket/back/models/{component-type-rate.json => component-type.json} (92%) rename modules/ticket/back/models/{component-rate.json => component.json} (92%) diff --git a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js index 37930f1b3..2a751697f 100644 --- a/modules/ticket/back/methods/sale/specs/updatePrice.spec.js +++ b/modules/ticket/back/methods/sale/specs/updatePrice.spec.js @@ -8,8 +8,8 @@ describe('sale updatePrice()', () => { let manaComponentId; beforeAll(async done => { - let componentRate = await app.models.ComponentRate.findOne({where: {code: 'mana'}}); - manaComponentId = componentRate.id; + let component = await app.models.Component.findOne({where: {code: 'mana'}}); + manaComponentId = component.id; originalSale = await app.models.Sale.findById(saleId); originalSalesPersonMana = await app.models.WorkerMana.findById(18); diff --git a/modules/ticket/back/methods/sale/updatePrice.js b/modules/ticket/back/methods/sale/updatePrice.js index 60a171e17..75e226c42 100644 --- a/modules/ticket/back/methods/sale/updatePrice.js +++ b/modules/ticket/back/methods/sale/updatePrice.js @@ -59,7 +59,7 @@ module.exports = Self => { let usesMana = await models.WorkerMana.findOne({where: {workerFk: salesPerson}, fields: 'amount'}, options); let componentCode = usesMana ? 'mana' : 'buyerDiscount'; - let discount = await models.ComponentRate.findOne({where: {code: componentCode}}, options); + let discount = await models.Component.findOne({where: {code: componentCode}}, options); let componentId = discount.id; let componentValue = newPrice - sale.price; diff --git a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js index 25ce90946..04570390d 100644 --- a/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js +++ b/modules/ticket/back/methods/ticket/specs/componentUpdate.spec.js @@ -13,7 +13,7 @@ describe('ticket componentUpdate()', () => { let componentOfSaleEight; beforeAll(async done => { - let deliveryComponenet = await app.models.ComponentRate.findOne({where: {code: 'delivery'}}); + let deliveryComponenet = await app.models.Component.findOne({where: {code: 'delivery'}}); deliveryComponentId = deliveryComponenet.id; componentOfSaleSeven = `SELECT value FROM vn.saleComponent WHERE saleFk = 7 AND componentFk = ${deliveryComponentId}`; componentOfSaleEight = `SELECT value FROM vn.saleComponent WHERE saleFk = 8 AND componentFk = ${deliveryComponentId}`; diff --git a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js index 75de1f538..111897efe 100644 --- a/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js +++ b/modules/ticket/back/methods/ticket/specs/updateDiscount.spec.js @@ -8,7 +8,7 @@ describe('sale updateDiscount()', () => { beforeAll(async done => { originalSale = await app.models.Sale.findById(originalSaleId); - let manaDiscount = await app.models.ComponentRate.findOne({where: {code: 'mana'}}); + let manaDiscount = await app.models.Component.findOne({where: {code: 'mana'}}); componentId = manaDiscount.id; let ticket = await app.models.Ticket.findById(originalSale.ticketFk); diff --git a/modules/ticket/back/methods/ticket/updateDiscount.js b/modules/ticket/back/methods/ticket/updateDiscount.js index 94ada046f..66b4d6f95 100644 --- a/modules/ticket/back/methods/ticket/updateDiscount.js +++ b/modules/ticket/back/methods/ticket/updateDiscount.js @@ -88,7 +88,7 @@ module.exports = Self => { fields: 'amount'}, options); const componentCode = usesMana ? 'mana' : 'buyerDiscount'; - const discountComponent = await models.ComponentRate.findOne({ + const discountComponent = await models.Component.findOne({ where: {code: componentCode}}, options); const componentId = discountComponent.id; diff --git a/modules/ticket/back/model-config.json b/modules/ticket/back/model-config.json index 3b38f1a16..10c10b134 100644 --- a/modules/ticket/back/model-config.json +++ b/modules/ticket/back/model-config.json @@ -5,10 +5,10 @@ "AnnualAverageInvoiced": { "dataSource": "vn" }, - "ComponentRate": { + "Component": { "dataSource": "vn" }, - "ComponentTypeRate": { + "ComponentType": { "dataSource": "vn" }, "Expedition": { diff --git a/modules/ticket/back/models/component-type-rate.json b/modules/ticket/back/models/component-type.json similarity index 92% rename from modules/ticket/back/models/component-type-rate.json rename to modules/ticket/back/models/component-type.json index c9b80f45c..ced725309 100644 --- a/modules/ticket/back/models/component-type-rate.json +++ b/modules/ticket/back/models/component-type.json @@ -1,5 +1,5 @@ { - "name": "ComponentTypeRate", + "name": "ComponentType", "base": "VnModel", "options": { "mysql": { diff --git a/modules/ticket/back/models/component-rate.json b/modules/ticket/back/models/component.json similarity index 92% rename from modules/ticket/back/models/component-rate.json rename to modules/ticket/back/models/component.json index 535b6086f..002b4804f 100644 --- a/modules/ticket/back/models/component-rate.json +++ b/modules/ticket/back/models/component.json @@ -1,5 +1,5 @@ { - "name": "ComponentRate", + "name": "Component", "base": "VnModel", "options": { "mysql": { @@ -34,7 +34,7 @@ "relations": { "componentType": { "type": "belongsTo", - "model": "ComponentTypeRate", + "model": "ComponentType", "foreignKey": "typeFk" } }, diff --git a/modules/ticket/back/models/sale-component.json b/modules/ticket/back/models/sale-component.json index 49edab2ae..3b7991fbb 100644 --- a/modules/ticket/back/models/sale-component.json +++ b/modules/ticket/back/models/sale-component.json @@ -25,9 +25,9 @@ "model": "Sale", "foreignKey": "saleFk" }, - "componentRate": { + "component": { "type": "belongsTo", - "model": "ComponentRate", + "model": "Component", "foreignKey": "componentFk" } } diff --git a/modules/ticket/front/component/index.html b/modules/ticket/front/component/index.html index 2a70baa9d..16db43a2e 100644 --- a/modules/ticket/front/component/index.html +++ b/modules/ticket/front/component/index.html @@ -45,19 +45,19 @@ - {{::component.componentRate.componentType.type}} + {{::saleComponent.component.componentType.type}} - {{::component.componentRate.name}} + {{::saleComponent.component.name}} - {{::component.value | currency: 'EUR':3}} + {{::saleComponent.value | currency: 'EUR':3}} - {{::sale.quantity * component.value | currency: 'EUR':3}} + {{::sale.quantity * saleComponent.value | currency: 'EUR':3}} diff --git a/modules/ticket/front/component/index.js b/modules/ticket/front/component/index.js index 9854305f6..027fdad77 100644 --- a/modules/ticket/front/component/index.js +++ b/modules/ticket/front/component/index.js @@ -15,7 +15,7 @@ class Controller { scope: { fields: ['componentFk', 'value'], include: { - relation: 'componentRate', + relation: 'component', scope: { fields: ['typeFk', 'name'], include: { @@ -38,9 +38,9 @@ class Controller { if (!sales) return; for (let sale of sales) { - for (let component of sale.components) { - if (component.componentRate.componentType.isBase) - sum += sale.quantity * component.value; + for (let saleComponent of sale.components) { + if (saleComponent.component.componentType.isBase) + sum += sale.quantity * saleComponent.value; } } diff --git a/modules/ticket/front/component/index.spec.js b/modules/ticket/front/component/index.spec.js index e75bf2bdb..4dd361b27 100644 --- a/modules/ticket/front/component/index.spec.js +++ b/modules/ticket/front/component/index.spec.js @@ -14,7 +14,7 @@ describe('ticket', () => { $scope.model.data = [{ components: [ { - componentRate: { + component: { name: 'valor de compra', componentType: { isBase: 1 @@ -23,7 +23,7 @@ describe('ticket', () => { value: 5 }, { - componentRate: { + component: { name: 'reparto', componentType: { isBase: 0 @@ -32,7 +32,7 @@ describe('ticket', () => { value: 5 }, { - componentRate: { + component: { name: 'recobro', componentType: { isBase: 0 @@ -46,7 +46,7 @@ describe('ticket', () => { { components: [ { - componentRate: { + component: { name: 'valor de compra', componentType: { isBase: 1 @@ -55,7 +55,7 @@ describe('ticket', () => { value: 1 }, { - componentRate: { + component: { name: 'reparto', componentType: { isBase: 0 @@ -64,7 +64,7 @@ describe('ticket', () => { value: 1 }, { - componentRate: { + component: { name: 'recobro', componentType: { isBase: 0