From 44e95a00c3bc775a1a554ffc4face2979e00a89c Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 17 Jun 2022 08:54:40 +0200 Subject: [PATCH] refactor: delete duplicated code --- .../back/methods/zone/getEventsFiltered.js | 8 ++-- modules/zone/front/events/index.js | 43 +++---------------- 2 files changed, 9 insertions(+), 42 deletions(-) diff --git a/modules/zone/back/methods/zone/getEventsFiltered.js b/modules/zone/back/methods/zone/getEventsFiltered.js index 0d0cf9376f..f466b4cfad 100644 --- a/modules/zone/back/methods/zone/getEventsFiltered.js +++ b/modules/zone/back/methods/zone/getEventsFiltered.js @@ -55,8 +55,8 @@ module.exports = Self => { SELECT e.* FROM vn.zoneExclusion e LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id - WHERE zoneFk = ? - AND dated BETWEEN ? AND ? + WHERE e.zoneFk = ? + AND e.dated BETWEEN ? AND ? AND eg.zoneExclusionFk IS NULL;`; const exclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions); @@ -64,8 +64,8 @@ module.exports = Self => { SELECT eg.*, e.zoneFk, e.dated, e.created, e.userFk FROM vn.zoneExclusion e LEFT JOIN vn.zoneExclusionGeo eg ON eg.zoneExclusionFk = e.id - WHERE zoneFk = ? - AND dated BETWEEN ? AND ? + WHERE e.zoneFk = ? + AND e.dated BETWEEN ? AND ? AND eg.zoneExclusionFk IS NOT NULL;`; const geoExclusions = await Self.rawSql(query, [zoneFk, started, ended], myOptions); diff --git a/modules/zone/front/events/index.js b/modules/zone/front/events/index.js index b22568e50a..e963b96e39 100644 --- a/modules/zone/front/events/index.js +++ b/modules/zone/front/events/index.js @@ -175,9 +175,7 @@ class Controller extends Section { return this.exclusionGeoCreate(); } case 'delete': - if (type == 'all') - return this.exclusionDelete(this.exclusions); - return this.exclusionGeoDelete(this.exclusionGeos); + return this.exclusionDelete(this.excludeSelected); } } @@ -236,41 +234,10 @@ class Controller extends Section { return req.then(() => this.refresh()); } - exclusionDelete(exclusions) { - const reqs = []; - - for (let exclusion of exclusions) { - if (!exclusion.id) continue; - const path = `${this.exclusionsPath}/${exclusion.id}`; - reqs.push(this.$http.delete(path)); - } - - this.$q.all(reqs) - .then(() => { - this.refresh(); - }); - } - - exclusionGeoDelete(exclusionsGeo) { - const reqs = []; - - for (let exclusionGeo of exclusionsGeo) { - if (!exclusionGeo.id) continue; - const path = `${this.exclusionsPath}/${exclusionGeo.zoneExclusionFk}`; - reqs.push(this.$http.delete(path)); - } - - this.$q.all(reqs) - .then(() => { - this.refresh(); - }); - } - - resetExclusions() { - this.excludeSelected = null; - this.isNew = null; - this.exclusions = []; - this.exclusionGeos = []; + exclusionDelete(exclusion) { + const path = `${this.exclusionsPath}/${exclusion.id}`; + return this.$http.delete(path) + .then(() => this.refresh()); } set excludeSearch(value) {