refactor: actualizada consulta sql
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-01-20 08:16:02 +01:00
parent 3f7dee63ac
commit 5d19da48e2
1 changed files with 21 additions and 24 deletions

View File

@ -30,31 +30,28 @@ module.exports = Self => {
if (typeof options == 'object') if (typeof options == 'object')
Object.assign(myOptions, options); Object.assign(myOptions, options);
const dated = new Date(date);
const dayName = dated.toString().split(' ')[0];
query = ` query = `
SELECT * SELECT *
FROM ( FROM (
SELECT SELECT
DISTINCT z.id, DISTINCT z.id,
z.name, z.name,
am.name agencyModeName, am.name agencyModeName,
IFNULL(ze.hour, z.hour) as hour, IFNULL(ze.hour, z.hour) as hour,
IFNULL(ze.price, z.price) as price IFNULL(ze.price, z.price) as price
FROM vn.zone z FROM vn.zone z
JOIN agencyMode am ON am.id = z.agencyModeFk JOIN vn.agencyMode am ON am.id = z.agencyModeFk
LEFT JOIN zoneEvent ze ON ze.zoneFk = z.id LEFT JOIN vn.zoneEvent ze ON ze.zoneFk = z.id
WHERE WHERE
( (
dated = ? ze.dated = ?
OR ? BETWEEN started AND ended OR ? BETWEEN ze.started AND ze.ended
OR weekDays LIKE ? OR ze.weekDays & (1 << WEEKDAY(?))
) )
AND z.id IN (?) AND z.id IN (?)
ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z ORDER BY type='day' DESC, type='range' DESC, type='indefinitely' DESC) z
GROUP BY z.id`; GROUP BY z.id;`;
return Self.rawSql(query, [date, date, dayName, zoneIds], myOptions); return Self.rawSql(query, [date, date, date, zoneIds], myOptions);
}; };
}; };