From 3247f35b90ae07a1d70533d0a9d6d1df6ce91e51 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 30 Aug 2021 14:14:21 +0200 Subject: [PATCH 1/2] 3075 - Show closure hour from an event --- modules/zone/back/models/zone.json | 5 +++ modules/zone/front/delivery-days/index.html | 2 +- modules/zone/front/delivery-days/index.js | 35 ++++++++++++++----- .../zone/front/delivery-days/index.spec.js | 26 ++++++++++---- 4 files changed, 53 insertions(+), 15 deletions(-) diff --git a/modules/zone/back/models/zone.json b/modules/zone/back/models/zone.json index bafef0a95..403a35359 100644 --- a/modules/zone/back/models/zone.json +++ b/modules/zone/back/models/zone.json @@ -62,6 +62,11 @@ "type": "hasMany", "model": "ZoneWarehouse", "foreignKey": "zoneFk" + }, + "closures": { + "type": "hasMany", + "model": "ZoneClosure", + "foreignKey": "zoneFk" } } } \ No newline at end of file diff --git a/modules/zone/front/delivery-days/index.html b/modules/zone/front/delivery-days/index.html index 79ec5c2b1..f01f4ec3f 100644 --- a/modules/zone/front/delivery-days/index.html +++ b/modules/zone/front/delivery-days/index.html @@ -1,7 +1,7 @@
+ on-selection="$ctrl.onSelection($event, $events, $days)">
diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 0c6fdffb7..036a2dacb 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -65,22 +65,41 @@ class Controller extends Section { }); } - onSelection($event, $events) { + onSelection($event, $events, $days) { if (!$events.length) return; - const zones = []; + const day = $days[0]; + const zonesIds = []; for (let event of $events) - zones.push(event.zoneFk); + zonesIds.push(event.zoneFk); this.$.zoneEvents.show($event.target); const zoneModel = this.$.zoneModel; zoneModel.applyFilter({ - include: { - relation: 'agencyMode', - scope: {fields: ['name']} - }, + include: [ + { + relation: 'agencyMode', + scope: {fields: ['name']} + }, + { + relation: 'events', + scope: { + where: {dated: day} + } + }, + ], where: { - id: {inq: zones} + id: {inq: zonesIds} + } + }).then(() => { + const data = zoneModel.data; + for (let row of data) { + console.log(row.events); + const [event] = row.events; + if (event && event.hour) + row.hour = event.hour; + if (event && event.price) + row.price = event.price; } }); } diff --git a/modules/zone/front/delivery-days/index.spec.js b/modules/zone/front/delivery-days/index.spec.js index 584d09330..c896021ed 100644 --- a/modules/zone/front/delivery-days/index.spec.js +++ b/modules/zone/front/delivery-days/index.spec.js @@ -99,7 +99,11 @@ describe('Zone Component vnZoneDeliveryDays', () => { it('should call the show() method and then call the applyFilter() method with the expected ids', () => { const zoneModel = controller.$.zoneModel; jest.spyOn(controller.$.zoneEvents, 'show'); - jest.spyOn(zoneModel, 'applyFilter'); + 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'); @@ -109,12 +113,22 @@ describe('Zone Component vnZoneDeliveryDays', () => { {zoneFk: 2}, {zoneFk: 8} ]; - controller.onSelection(event, events); + + const day = new Date(); + controller.onSelection(event, events, [day]); const expectedFilter = { - include: { - relation: 'agencyMode', - scope: {fields: ['name']} - }, + include: [ + { + relation: 'agencyMode', + scope: {fields: ['name']} + }, + { + relation: 'events', + scope: { + where: {dated: day} + } + } + ], where: { id: {inq: [1, 2, 8]} } From 4dc107bc58f65773d4ce63c662f339dbf1bab777 Mon Sep 17 00:00:00 2001 From: joan Date: Mon, 30 Aug 2021 14:51:02 +0200 Subject: [PATCH 2/2] Removed console.log() --- modules/zone/front/delivery-days/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/zone/front/delivery-days/index.js b/modules/zone/front/delivery-days/index.js index 036a2dacb..12b1c57b1 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -94,7 +94,6 @@ class Controller extends Section { }).then(() => { const data = zoneModel.data; for (let row of data) { - console.log(row.events); const [event] = row.events; if (event && event.hour) row.hour = event.hour;