From 5d19da48e2dd4685701bc25c2f4980e3dc70025b Mon Sep 17 00:00:00 2001 From: vicent Date: Fri, 20 Jan 2023 08:16:02 +0100 Subject: [PATCH] refactor: actualizada consulta sql --- .../zone/back/methods/zone/getZoneClosing.js | 45 +++++++++---------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 0e3872c1b..8714e8e65 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -30,31 +30,28 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const dated = new Date(date); - const dayName = dated.toString().split(' ')[0]; - query = ` - SELECT * - FROM ( - SELECT - DISTINCT z.id, - z.name, - am.name agencyModeName, - 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 weekDays LIKE ? - ) - AND z.id IN (?) - ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z - GROUP BY z.id`; + SELECT * + FROM ( + SELECT + DISTINCT z.id, + z.name, + am.name agencyModeName, + IFNULL(ze.hour, z.hour) as hour, + IFNULL(ze.price, z.price) as price + FROM vn.zone z + JOIN vn.agencyMode am ON am.id = z.agencyModeFk + LEFT JOIN vn.zoneEvent ze ON ze.zoneFk = z.id + WHERE + ( + ze.dated = ? + OR ? BETWEEN ze.started AND ze.ended + OR ze.weekDays & (1 << WEEKDAY(?)) + ) + AND z.id IN (?) + ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z + GROUP BY z.id;`; - return Self.rawSql(query, [date, date, dayName, zoneIds], myOptions); + return Self.rawSql(query, [date, date, date, zoneIds], myOptions); }; };