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..12b1c57b1 100644 --- a/modules/zone/front/delivery-days/index.js +++ b/modules/zone/front/delivery-days/index.js @@ -65,22 +65,40 @@ 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) { + 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]} }