From 3f483d36f2f420db671fd7d4e39d71cedda30269 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 28 Feb 2022 14:28:16 +0100 Subject: [PATCH 01/13] refactor(order_search-panel): change orderFk to ticketFk --- modules/order/back/methods/order/filter.js | 14 +++++++------- modules/order/front/main/index.html | 2 +- modules/order/front/search-panel/index.html | 6 +++--- modules/order/front/search-panel/locale/es.yml | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index 27cacdd620..a4d0c0f8e4 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -18,7 +18,7 @@ module.exports = Self => { }, { arg: 'search', type: 'string', - description: `If it's and integer searchs by id, otherwise it searchs by nickname` + description: `If it's and integer searchs by ticket id, otherwise it searchs by nickname` }, { arg: 'from', type: 'date', @@ -36,9 +36,9 @@ module.exports = Self => { type: 'integer', description: 'The client id' }, { - arg: 'ticketFk', + arg: 'orderFk', type: 'integer', - description: 'The ticket id' + description: 'The order id' }, { arg: 'agencyModeFk', type: 'integer', @@ -103,7 +103,7 @@ module.exports = Self => { switch (param) { case 'search': return /^\d+$/.test(value) - ? {'o.id': value} + ? {'t.id': value} : {or: [ {'c.name': {like: `%${value}%`}} ]}; @@ -119,8 +119,8 @@ module.exports = Self => { return {'o.agency_id': value}; case 'sourceApp': return {'o.source_app': value}; - case 'ticketFk': - return {'ot.ticketFk': value}; + case 'orderFk': + return {'o.id': value}; case 'isConfirmed': return {'o.confirmed': value ? 1 : 0}; case 'myTeam': @@ -131,7 +131,7 @@ module.exports = Self => { case 'showEmpty': return {'o.total': {neq: value}}; case 'id': - param = `o.${param}`; + param = `t.${param}`; return {[param]: value}; } }); diff --git a/modules/order/front/main/index.html b/modules/order/front/main/index.html index f3b72adb2a..1f6c7434c8 100644 --- a/modules/order/front/main/index.html +++ b/modules/order/front/main/index.html @@ -9,7 +9,7 @@ diff --git a/modules/order/front/search-panel/index.html b/modules/order/front/search-panel/index.html index c622dd1523..a3ed9e5a5b 100644 --- a/modules/order/front/search-panel/index.html +++ b/modules/order/front/search-panel/index.html @@ -5,7 +5,7 @@ vn-one label="General search" ng-model="filter.search" - info="Search orders by id" + info="Search orders by ticket id" vn-focus> @@ -51,8 +51,8 @@ + label="Order id" + ng-model="filter.orderFk"> Date: Tue, 1 Mar 2022 10:44:04 +0100 Subject: [PATCH 02/13] feat(supplier-account): isPayMethodChecked false when change model --- .../models/specs/supplier-account.spec.js | 63 ++++++++++++++----- .../supplier/back/models/supplier-account.js | 12 ++++ 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/modules/supplier/back/models/specs/supplier-account.spec.js b/modules/supplier/back/models/specs/supplier-account.spec.js index f56e70a89c..083c681ac5 100644 --- a/modules/supplier/back/models/specs/supplier-account.spec.js +++ b/modules/supplier/back/models/specs/supplier-account.spec.js @@ -1,16 +1,28 @@ -const app = require('vn-loopback/server/server'); +const models = require('vn-loopback/server/server').models; const LoopBackContext = require('loopback-context'); describe('loopback model Supplier-account', () => { describe('create', () => { const supplierId = 1; const bankEntityId = 2100; + const activeCtx = { + accessToken: {userId: 5}, + http: { + req: { + headers: {origin: 'http://localhost'} + } + } + }; + activeCtx.http.req.__ = value => { + return value; + }; + it('should throw an error when attempting to set an invalid iban account', async() => { let error; const expectedError = 'The IBAN does not have the correct format'; const iban = 'incorrect format'; try { - await app.models.SupplierAccount.create( + await models.SupplierAccount.create( { supplierFk: supplierId, bankEntityFk: bankEntityId, @@ -26,27 +38,16 @@ describe('loopback model Supplier-account', () => { }); it('should create a valid supplier account', async() => { - const tx = await app.models.Claim.beginTransaction({}); + const tx = await models.SupplierAccount.beginTransaction({}); try { const options = {transaction: tx}; const iban = 'ES91 2100 0418 4502 0005 1332'; - const activeCtx = { - accessToken: {userId: 5}, - http: { - req: { - headers: {origin: 'http://localhost'} - } - } - }; - activeCtx.http.req.__ = value => { - return value; - }; - spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ active: activeCtx }); - const createdSupplierAccount = await app.models.SupplierAccount.create({ + + const createdSupplierAccount = await models.SupplierAccount.create({ supplierFk: supplierId, bankEntityFk: bankEntityId, iban: iban @@ -60,5 +61,35 @@ describe('loopback model Supplier-account', () => { throw e; } }); + + it('should change isPayMethodChecked to false', async() => { + const tx = await models.SupplierAccount.beginTransaction({}); + try { + const options = {transaction: tx}; + const iban = 'ES91 2100 0418 4502 0005 1332'; + + spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ + active: activeCtx + }); + + const supplierBefore = await models.Supplier.findById(supplierId, null, options); + + await models.SupplierAccount.create({ + supplierFk: supplierId, + bankEntityFk: bankEntityId, + iban: iban + }, + options); + + const supplierAfter = await models.Supplier.findById(supplierId, null, options); + + expect(supplierBefore.isPayMethodChecked).toBeTruthy(); + expect(supplierAfter.isPayMethodChecked).toBeFalsy(); + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); }); }); diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js index c8b2f0595b..ae93ef83b1 100644 --- a/modules/supplier/back/models/supplier-account.js +++ b/modules/supplier/back/models/supplier-account.js @@ -34,4 +34,16 @@ module.exports = Self => { ctx.instance.iban + ', entidad: ' + bankEntity.name + ', bic: ' + bankEntity.bic }); }); + + Self.observe('after save', async ctx => { + const options = {}; + + // Check for transactions + if (ctx.options && ctx.options.transaction) + options.transaction = ctx.options.transaction; + const supplier = await Self.app.models.Supplier.findById(ctx.instance.supplierFk, options); + + if (supplier.isPayMethodChecked) + await supplier.updateAttribute('isPayMethodChecked', false, options); + }); }; From a27a48f251a17a6c7a9b05d08dc03f9b13305167 Mon Sep 17 00:00:00 2001 From: alexm Date: Tue, 1 Mar 2022 10:44:46 +0100 Subject: [PATCH 03/13] fix(supplier_account): fix setWireTransfer and add test --- modules/supplier/front/account/index.js | 10 +++++++ modules/supplier/front/account/index.spec.js | 28 ++++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/modules/supplier/front/account/index.js b/modules/supplier/front/account/index.js index 6c6e77d2ee..5629e65d36 100644 --- a/modules/supplier/front/account/index.js +++ b/modules/supplier/front/account/index.js @@ -45,6 +45,16 @@ class Controller extends Section { this.$.payMethodToTransfer.show(); }); } + + setWireTransfer() { + const params = { + id: this.$params.id, + payMethodFk: this.wireTransferFk + }; + const query = `Suppliers/${this.$params.id}`; + return this.$http.patch(query, params) + .then(() => this.$.watcher.notifySaved()); + } } ngModule.vnComponent('vnSupplierAccount', { diff --git a/modules/supplier/front/account/index.spec.js b/modules/supplier/front/account/index.spec.js index 5c824907f6..ad29d1abc9 100644 --- a/modules/supplier/front/account/index.spec.js +++ b/modules/supplier/front/account/index.spec.js @@ -5,9 +5,12 @@ import crudModel from 'core/mocks/crud-model'; describe('Supplier Component vnSupplierAccount', () => { let $scope; let controller; + let $httpBackend; + beforeEach(ngModule('supplier')); beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { + $httpBackend = _$httpBackend_; $scope = $rootScope.$new(); $scope.model = crudModel; $scope.watcher = watcher; @@ -66,5 +69,30 @@ describe('Supplier Component vnSupplierAccount', () => { }).catch(done.fail); }); }); + + describe('setWireTransfer()', () => { + it(`should make HTTP PATCH request to set wire transfer and call notifySaved`, () => { + const supplierId = 1; + const params = { + id: supplierId, + payMethodFk: 2 + }; + const response = { + data: {id: 2} + }; + const uri = 'payMethods/findOne?filter=%7B%22where%22:%7B%22code%22:%22wireTransfer%22%7D%7D'; + jest.spyOn($scope.watcher, 'notifySaved'); + + controller.$params.id = supplierId; + controller.wireTransferFk = 2; + controller.supplier = {payMethodFk: 1}; + $httpBackend.expectGET(uri).respond(response); + $httpBackend.expectPATCH(`Suppliers/${supplierId}`, params).respond(); + controller.setWireTransfer(); + $httpBackend.flush(); + + expect($scope.watcher.notifySaved).toHaveBeenCalledWith(); + }); + }); }); From e082d185646b0fe057b8c3012502c262426a434d Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 3 Mar 2022 13:03:43 +0100 Subject: [PATCH 04/13] change description --- modules/order/back/methods/order/filter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/order/back/methods/order/filter.js b/modules/order/back/methods/order/filter.js index a4d0c0f8e4..008c0e5c95 100644 --- a/modules/order/back/methods/order/filter.js +++ b/modules/order/back/methods/order/filter.js @@ -18,7 +18,7 @@ module.exports = Self => { }, { arg: 'search', type: 'string', - description: `If it's and integer searchs by ticket id, otherwise it searchs by nickname` + description: `The general search by ticket id or nickname` }, { arg: 'from', type: 'date', From 6748426f670ed5878c86f249880f530fc0a7fb89 Mon Sep 17 00:00:00 2001 From: alexm Date: Thu, 3 Mar 2022 13:48:18 +0100 Subject: [PATCH 05/13] correct loopback form --- modules/supplier/back/models/supplier-account.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/supplier/back/models/supplier-account.js b/modules/supplier/back/models/supplier-account.js index ae93ef83b1..dc6c6d5fd4 100644 --- a/modules/supplier/back/models/supplier-account.js +++ b/modules/supplier/back/models/supplier-account.js @@ -38,10 +38,9 @@ module.exports = Self => { Self.observe('after save', async ctx => { const options = {}; - // Check for transactions if (ctx.options && ctx.options.transaction) options.transaction = ctx.options.transaction; - const supplier = await Self.app.models.Supplier.findById(ctx.instance.supplierFk, options); + const supplier = await Self.app.models.Supplier.findById(ctx.instance.supplierFk, null, options); if (supplier.isPayMethodChecked) await supplier.updateAttribute('isPayMethodChecked', false, options); From a434d9268bf9018c9f72d072d36c1ee45851d8bb Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 4 Mar 2022 11:48:18 +0100 Subject: [PATCH 06/13] fix(zone_upcoming-deliveries): fix backgroundcolor --- modules/zone/front/upcoming-deliveries/style.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/modules/zone/front/upcoming-deliveries/style.scss b/modules/zone/front/upcoming-deliveries/style.scss index d3f33260ad..b52231a099 100644 --- a/modules/zone/front/upcoming-deliveries/style.scss +++ b/modules/zone/front/upcoming-deliveries/style.scss @@ -15,6 +15,7 @@ vn-upcoming-deliveries { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; + background-color: $color-bg; } vn-table vn-th.waste-family, From a658969afa4a2c1af565ac55e38ab37bfd6e4a60 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 4 Mar 2022 12:24:01 +0100 Subject: [PATCH 07/13] feat(zone_delivery-days): get real closing hour --- .../zone/back/methods/zone/getZoneClosing.js | 68 +++++++++++++++++++ modules/zone/back/models/zone.js | 1 + modules/zone/front/delivery-days/index.html | 14 +--- modules/zone/front/delivery-days/index.js | 37 +++------- .../zone/front/delivery-days/index.spec.js | 35 +++------- 5 files changed, 90 insertions(+), 65 deletions(-) create mode 100644 modules/zone/back/methods/zone/getZoneClosing.js diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js new file mode 100644 index 0000000000..02286e6d52 --- /dev/null +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -0,0 +1,68 @@ +module.exports = Self => { + Self.remoteMethod('getZoneClosing', { + description: 'Get events filtered for zone and date', + accepts: [ + { + arg: 'zonesId', + type: ['number'], + description: 'The zones id', + required: true + }, + { + arg: 'date', + type: 'date', + description: 'The date calendar', + } + ], + returns: { + type: 'object', + root: true + }, + http: { + path: `/getZoneClosing`, + verb: 'POST' + } + }); + + Self.getZoneClosing = async(zonesId, date, options) => { + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + const params = []; + const paramsSql = [date, date, date]; + for (id of zonesId) { + params.push('?'); + paramsSql.push(id); + } + + const paramsString = params.join(); + query = ` + SELECT * + FROM ( + SELECT + DISTINCT z.id, + z.name, + am.name agencyModeName, + type, + IFNULL(ze.hour, z.hour) as hour, + IFNULL(ze.price, z.price) as price + FROM vn.zone z + JOIN agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN zoneEvent ze ON ze.zoneFk = z.id + WHERE + ( + dated = ? + OR ? BETWEEN started AND ended + OR INSTR(weekDays, SUBSTRING(DAYNAME(?), 1, 3) ) > 0 + ) + AND z.id IN (${paramsString}) + ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z + GROUP BY z.id + `; + + const zones = await Self.rawSql(query, paramsSql, myOptions); + return zones; + }; +}; diff --git a/modules/zone/back/models/zone.js b/modules/zone/back/models/zone.js index 9771c958b3..ef1c8c5d95 100644 --- a/modules/zone/back/models/zone.js +++ b/modules/zone/back/models/zone.js @@ -7,6 +7,7 @@ module.exports = Self => { require('../methods/zone/getUpcomingDeliveries')(Self); require('../methods/zone/deleteZone')(Self); require('../methods/zone/includingExpired')(Self); + require('../methods/zone/getZoneClosing')(Self); Self.validatesPresenceOf('agencyModeFk', { message: `Agency cannot be blank` diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index f01f4ec3f0..1c1a9b1b36 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -52,23 +52,15 @@ - - -
Zones
- + Id @@ -81,7 +73,7 @@ {{::zone.id}} diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 12b1c57b17..d4bb3b3356 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -74,33 +74,16 @@ class Controller extends Section { zonesIds.push(event.zoneFk); this.$.zoneEvents.show($event.target); - const zoneModel = this.$.zoneModel; - zoneModel.applyFilter({ - include: [ - { - relation: 'agencyMode', - scope: {fields: ['name']} - }, - { - relation: 'events', - scope: { - where: {dated: day} - } - }, - ], - where: { - id: {inq: zonesIds} - } - }).then(() => { - const data = zoneModel.data; - for (let row of data) { - const [event] = row.events; - if (event && event.hour) - row.hour = event.hour; - if (event && event.price) - row.price = event.price; - } - }); + + const params = { + zonesId: zonesIds, + date: day + }; + + this.$http.post(`Zones/getZoneClosing`, params) + .then(res => { + this.zoneClosing = res.data; + }); } preview(zone) { diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index c896021ed6..c03da585f2 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -96,14 +96,8 @@ describe('Zone Component vnZoneDeliveryDays', () => { expect(controller.$.zoneEvents.show).not.toHaveBeenCalled(); }); - it('should call the show() method and then call the applyFilter() method with the expected ids', () => { - const zoneModel = controller.$.zoneModel; + xit('should call the show() method and call getZoneClosing with the expected ids', () => { jest.spyOn(controller.$.zoneEvents, 'show'); - jest.spyOn(zoneModel, 'applyFilter').mockReturnValue(new Promise(resolve => { - zoneModel.data = [ - {id: 1, events: [{price: 25}]} - ]; - })); const event = new Event('click'); const target = document.createElement('div'); @@ -113,29 +107,16 @@ describe('Zone Component vnZoneDeliveryDays', () => { {zoneFk: 2}, {zoneFk: 8} ]; - - const day = new Date(); - controller.onSelection(event, events, [day]); - const expectedFilter = { - include: [ - { - relation: 'agencyMode', - scope: {fields: ['name']} - }, - { - relation: 'events', - scope: { - where: {dated: day} - } - } - ], - where: { - id: {inq: [1, 2, 8]} - } + const params = { + zonesId: [1, 2, 8], + date: [day][0] }; + const day = new Date(); + $httpBackend.expect('POST', 'Zones/getZoneClosing', params).respond({}); + controller.onSelection(event, events, [day]); expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target); - expect(zoneModel.applyFilter).toHaveBeenCalledWith(expectedFilter); + expect(controller.zoneClosing).toBeDefined(); }); }); }); From 2c853a7885cd7f9412d335ff8a5b9a85374001e5 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 08:02:59 +0100 Subject: [PATCH 08/13] test(zone): getZoneClosing() front and back --- .../zone/back/methods/zone/getZoneClosing.js | 4 +--- .../methods/zone/specs/getZoneClosing.spec.js | 23 +++++++++++++++++++ modules/zone/front/delivery-days/index.js | 4 +--- .../zone/front/delivery-days/index.spec.js | 12 ++++++---- 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 modules/zone/back/methods/zone/specs/getZoneClosing.spec.js diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 02286e6d52..8d9ccdb215 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -45,7 +45,6 @@ module.exports = Self => { DISTINCT z.id, z.name, am.name agencyModeName, - type, IFNULL(ze.hour, z.hour) as hour, IFNULL(ze.price, z.price) as price FROM vn.zone z @@ -62,7 +61,6 @@ module.exports = Self => { GROUP BY z.id `; - const zones = await Self.rawSql(query, paramsSql, myOptions); - return zones; + return await Self.rawSql(query, paramsSql, myOptions); }; }; diff --git a/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js b/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js new file mode 100644 index 0000000000..0c479dda09 --- /dev/null +++ b/modules/zone/back/methods/zone/specs/getZoneClosing.spec.js @@ -0,0 +1,23 @@ +const models = require('vn-loopback/server/server').models; + +describe('zone getZoneClosing()', () => { + it('should return closing time of zones', async() => { + const tx = await models.Zone.beginTransaction({}); + + try { + const options = {transaction: tx}; + const date = new Date(); + const today = date.toISOString().split('T')[0]; + + const result = await models.Zone.getZoneClosing([1, 2, 3], today, options); + + expect(result.length).toEqual(3); + expect(result[0].hour).toBeDefined(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index d4bb3b3356..21c65678f8 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -81,9 +81,7 @@ class Controller extends Section { }; this.$http.post(`Zones/getZoneClosing`, params) - .then(res => { - this.zoneClosing = res.data; - }); + .then(res => this.zoneClosing = res.data); } preview(zone) { diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index c03da585f2..3d71bc93f0 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -96,12 +96,14 @@ describe('Zone Component vnZoneDeliveryDays', () => { expect(controller.$.zoneEvents.show).not.toHaveBeenCalled(); }); - xit('should call the show() method and call getZoneClosing with the expected ids', () => { + it('should call the show() method and call getZoneClosing() with the expected ids', () => { jest.spyOn(controller.$.zoneEvents, 'show'); const event = new Event('click'); const target = document.createElement('div'); target.dispatchEvent(event); + + const day = new Date(); const events = [ {zoneFk: 1}, {zoneFk: 2}, @@ -111,12 +113,14 @@ describe('Zone Component vnZoneDeliveryDays', () => { zonesId: [1, 2, 8], date: [day][0] }; - const day = new Date(); - $httpBackend.expect('POST', 'Zones/getZoneClosing', params).respond({}); + const response = [{id: 1, hour: ''}]; + + $httpBackend.when('POST', 'Zones/getZoneClosing', params).respond({response}); controller.onSelection(event, events, [day]); + $httpBackend.flush(); expect(controller.$.zoneEvents.show).toHaveBeenCalledWith(target); - expect(controller.zoneClosing).toBeDefined(); + expect(controller.zoneClosing.id).toEqual(response.id); }); }); }); From dedbccae198b89a082168a483896e235daef20c5 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 08:07:34 +0100 Subject: [PATCH 09/13] description --- modules/zone/back/methods/zone/getZoneClosing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 8d9ccdb215..849aa50080 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -1,6 +1,6 @@ module.exports = Self => { Self.remoteMethod('getZoneClosing', { - description: 'Get events filtered for zone and date', + description: 'Get zone events filtered for date and prioritized by type', accepts: [ { arg: 'zonesId', From b421038bbef99cea8802b3cac1d66ac60594d6c1 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 08:11:21 +0100 Subject: [PATCH 10/13] typo --- modules/zone/back/methods/zone/getZoneClosing.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 849aa50080..56fb3b7a6c 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -58,8 +58,7 @@ module.exports = Self => { ) AND z.id IN (${paramsString}) ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z - GROUP BY z.id - `; + GROUP BY z.id`; return await Self.rawSql(query, paramsSql, myOptions); }; From a136d8b03d6f6b25629dfa587cb42899233c4d2e Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 10:10:45 +0100 Subject: [PATCH 11/13] accept array in params --- modules/ticket/back/methods/sale/payBack.js | 13 ++++--------- .../ticket/back/methods/sale/recalculatePrice.js | 9 ++------- modules/zone/back/methods/zone/getZoneClosing.js | 12 ++---------- 3 files changed, 8 insertions(+), 26 deletions(-) diff --git a/modules/ticket/back/methods/sale/payBack.js b/modules/ticket/back/methods/sale/payBack.js index 3bb0564659..098da4d5a8 100644 --- a/modules/ticket/back/methods/sale/payBack.js +++ b/modules/ticket/back/methods/sale/payBack.js @@ -40,7 +40,6 @@ module.exports = Self => { try { const salesIds = []; - const params = []; const userId = ctx.req.accessToken.userId; const isClaimManager = await Self.app.models.Account.hasRole(userId, 'claimManager'); @@ -50,23 +49,19 @@ module.exports = Self => { if (!hasValidRole) throw new UserError(`You don't have privileges to create pay back`); - sales.forEach(sale => { + for (let sale of sales) salesIds.push(sale.id); - params.push('?'); - }); - - const paramsString = params.join(); const query = ` DROP TEMPORARY TABLE IF EXISTS tmp.sale; CREATE TEMPORARY TABLE tmp.sale SELECT s.id, s.itemFk, - s.quantity, s.concept, s.price, s.discount FROM sale s - WHERE s.id IN (${paramsString}); - CALL vn.ticket_doRefund(${ticketId}, @newTicket); + WHERE s.id IN (?); + CALL vn.ticket_doRefund(?, @newTicket); DROP TEMPORARY TABLE tmp.sale;`; - await Self.rawSql(query, salesIds, myOptions); + await Self.rawSql(query, [salesIds, ticketId], myOptions); const [newTicket] = await Self.rawSql('SELECT @newTicket id', null, myOptions); ticketId = newTicket.id; diff --git a/modules/ticket/back/methods/sale/recalculatePrice.js b/modules/ticket/back/methods/sale/recalculatePrice.js index 8a390223da..59c7d3535c 100644 --- a/modules/ticket/back/methods/sale/recalculatePrice.js +++ b/modules/ticket/back/methods/sale/recalculatePrice.js @@ -35,11 +35,8 @@ module.exports = Self => { try { const salesIds = []; - const params = []; - sales.forEach(sale => { + for (let sale of sales) salesIds.push(sale.id); - params.push('?'); - }); const isEditable = await models.Ticket.isEditable(ctx, sales[0].ticketFk, myOptions); if (!isEditable) @@ -49,14 +46,12 @@ module.exports = Self => { if (!canEditSale) throw new UserError(`Sale(s) blocked, please contact production`); - const paramsString = params.join(); - const query = ` DROP TEMPORARY TABLE IF EXISTS tmp.recalculateSales; CREATE TEMPORARY TABLE tmp.recalculateSales SELECT s.id FROM sale s - WHERE s.id IN (${paramsString}); + WHERE s.id IN (?); CALL vn.sale_recalcComponent(null); DROP TEMPORARY TABLE tmp.recalculateSales;`; diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 56fb3b7a6c..fae43c0dc2 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -30,14 +30,6 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const params = []; - const paramsSql = [date, date, date]; - for (id of zonesId) { - params.push('?'); - paramsSql.push(id); - } - - const paramsString = params.join(); query = ` SELECT * FROM ( @@ -56,10 +48,10 @@ module.exports = Self => { OR ? BETWEEN started AND ended OR INSTR(weekDays, SUBSTRING(DAYNAME(?), 1, 3) ) > 0 ) - AND z.id IN (${paramsString}) + AND z.id IN (?) ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z GROUP BY z.id`; - return await Self.rawSql(query, paramsSql, myOptions); + return Self.rawSql(query, [date, date, date, zonesId], myOptions); }; }; From 56bdb85af50fc1c0daf4c2405f773289b5245e29 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 10:28:55 +0100 Subject: [PATCH 12/13] translations --- modules/zone/back/methods/zone/getEventsFiltered.js | 4 ++-- modules/zone/back/methods/zone/getZoneClosing.js | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/modules/zone/back/methods/zone/getEventsFiltered.js b/modules/zone/back/methods/zone/getEventsFiltered.js index 2788f45d04..5e9cbae5ac 100644 --- a/modules/zone/back/methods/zone/getEventsFiltered.js +++ b/modules/zone/back/methods/zone/getEventsFiltered.js @@ -11,12 +11,12 @@ module.exports = Self => { { arg: 'started', type: 'date', - description: 'The date calendar start', + description: 'The calendar date start', }, { arg: 'ended', type: 'date', - description: 'The date calendar end', + description: 'The calendar date end', } ], returns: { diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index fae43c0dc2..6afb534089 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -3,15 +3,15 @@ module.exports = Self => { description: 'Get zone events filtered for date and prioritized by type', accepts: [ { - arg: 'zonesId', + arg: 'zoneIds', type: ['number'], - description: 'The zones id', + description: 'The zone identifiers or ids', required: true }, { arg: 'date', type: 'date', - description: 'The date calendar', + description: 'The calendar date', } ], returns: { @@ -24,7 +24,7 @@ module.exports = Self => { } }); - Self.getZoneClosing = async(zonesId, date, options) => { + Self.getZoneClosing = async(zoneIds, date, options) => { const myOptions = {}; if (typeof options == 'object') @@ -52,6 +52,6 @@ module.exports = Self => { ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z GROUP BY z.id`; - return Self.rawSql(query, [date, date, date, zonesId], myOptions); + return Self.rawSql(query, [date, date, date, zoneIds], myOptions); }; }; From 0359e05defca3352de61d09e39f993ea91c27eb9 Mon Sep 17 00:00:00 2001 From: alexm Date: Mon, 7 Mar 2022 11:22:16 +0100 Subject: [PATCH 13/13] description --- modules/zone/back/methods/zone/getZoneClosing.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 6afb534089..2a00882037 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -5,7 +5,7 @@ module.exports = Self => { { arg: 'zoneIds', type: ['number'], - description: 'The zone identifiers or ids', + description: 'The zone ids', required: true }, {