diff --git a/modules/zone/back/methods/zone/getEventsFiltered.js b/modules/zone/back/methods/zone/getEventsFiltered.js new file mode 100644 index 000000000..ea339d88f --- /dev/null +++ b/modules/zone/back/methods/zone/getEventsFiltered.js @@ -0,0 +1,21 @@ +module.exports = Self => { + Self.remoteMethodCtx('getEventsFiltered', { + description: 'Get events filtered for zone and date', + accessType: 'READ', + returns: { + type: 'object', + root: true + }, + http: { + path: `/getEventsFiltered`, + verb: 'GET' + } + }); + + Self.getEventsFiltered = async(zoneFk, started, ended) => { + query = `CALL vn.zone_getEventsFiltered(?,?,?)`; + const [events, exclusions] = await Self.rawSql(query, [zoneFk, started, ended]); + console.log(events); + return {events, exclusions}; + }; +}; diff --git a/modules/zone/back/models/zone.js b/modules/zone/back/models/zone.js index 0b1b9d106..9771c958b 100644 --- a/modules/zone/back/models/zone.js +++ b/modules/zone/back/models/zone.js @@ -2,6 +2,7 @@ module.exports = Self => { require('../methods/zone/clone')(Self); require('../methods/zone/getLeaves')(Self); require('../methods/zone/getEvents')(Self); + require('../methods/zone/getEventsFiltered')(Self); require('../methods/zone/toggleIsIncluded')(Self); require('../methods/zone/getUpcomingDeliveries')(Self); require('../methods/zone/deleteZone')(Self); diff --git a/modules/zone/front/events/index.js b/modules/zone/front/events/index.js index 29b534c0c..e10c1c6f1 100644 --- a/modules/zone/front/events/index.js +++ b/modules/zone/front/events/index.js @@ -12,22 +12,22 @@ class Controller extends Section { this.refresh(); } - get path() { - return `Zones/${this.$params.id}/events`; - } - - get exclusionsPath() { - return `Zones/${this.$params.id}/exclusions`; - } - refresh() { - let data = {}; - this.$q.all([ - this.$http.get(this.path) - .then(res => data.events = res.data), - this.$http.get(this.exclusionsPath) - .then(res => data.exclusions = res.data) - ]).finally(() => { + this.$.data = null; + let params = { + ended: '2022-01-31', + started: '2021-10-01', + zoneFk: 10 + }; + let ended = '2022-01-31'; + let started = '2021-10-01'; + let zoneFk = 10; + // let filter = encodeURIComponent(JSON.stringify(params)); + let path = `Zones/getEventsFiltered?zoneFk=${zoneFk}&started=${started}&ended=${ended}`; + console.log(path); + this.$http.get(path).then(res => { + console.log(res.data); + let data = res.data; this.$.data = data; }); }