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,9 +30,6 @@ 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 (
@ -43,18 +40,18 @@ module.exports = Self => {
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
JOIN vn.agencyMode am ON am.id = z.agencyModeFk
LEFT JOIN vn.zoneEvent ze ON ze.zoneFk = z.id
WHERE
(
dated = ?
OR ? BETWEEN started AND ended
OR weekDays LIKE ?
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`;
GROUP BY z.id;`;
return Self.rawSql(query, [date, date, dayName, zoneIds], myOptions);
return Self.rawSql(query, [date, date, date, zoneIds], myOptions);
};
};