diff --git a/modules/zone/back/methods/zone/getZoneClosing.js b/modules/zone/back/methods/zone/getZoneClosing.js index 8714e8e65..76706b55c 100644 --- a/modules/zone/back/methods/zone/getZoneClosing.js +++ b/modules/zone/back/methods/zone/getZoneClosing.js @@ -31,27 +31,30 @@ module.exports = Self => { Object.assign(myOptions, options); 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 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;`; + 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.type = 'day' + AND ze.dated = ? + ) OR ( + ze.type != 'day' + AND ze.weekDays & (1 << WEEKDAY(?)) + AND (ze.started IS NULL OR ? >= ze.started) + AND (ze.ended IS NULL OR ? <= ze.ended) + )) + 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, date, zoneIds], myOptions); + return Self.rawSql(query, [date, date, date, date, zoneIds], myOptions); }; };