From 1958d443b98b8e235ce8df57a6256430240936c8 Mon Sep 17 00:00:00 2001 From: Cheryl Chen Date: Fri, 2 Feb 2024 11:13:27 -0800 Subject: [PATCH] fixed mapping december --- routes/publishedSchedule.js | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 8073522..d275316 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -33,36 +33,24 @@ publishedScheduleRouter.get('/', async (req, res) => { // GET /published-schedule/season - returns rows that match the season publishedScheduleRouter.get('/season', async (req, res) => { try { - // start and end times for the first interval (ie. JAN 1 2012 -> FEB 29 2012) let startTime; let endTime; - // start and end times for the second interval (ie. DEC 1 2012 -> DEC 31 2012) - let secondstartTime; - let secondendTime; const { season, year } = req.query; // getting the intervals for each season if (season.toLowerCase() === 'winter') { - startTime = `${year}-01-01`; + startTime = `${year - 1}-12-01`; endTime = `${year}-02-29`; - secondstartTime = `${year}-12-01`; - secondendTime = `${year}-12-31`; } else if (season.toLowerCase() === 'spring') { startTime = `${year}-03-01`; endTime = `${year}-05-31`; - secondstartTime = `${year}-03-01`; - secondendTime = `${year}-05-31`; } else if (season.toLowerCase() === 'summer') { startTime = `${year}-06-01`; endTime = `${year}-08-31`; - secondstartTime = `${year}-06-01`; - secondendTime = `${year}-08-31`; } else { startTime = `${year}-09-01`; endTime = `${year}-11-30`; - secondstartTime = `${year}-09-01`; - secondendTime = `${year}-11-30`; } const seasonResult = await db.query( @@ -83,15 +71,14 @@ publishedScheduleRouter.get('/season', async (req, res) => { FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id WHERE - (DATE(start_time) >= $1::date AND DATE(start_time) <= $2::date) OR - (DATE(start_time) >= $3::date AND DATE(start_time) <= $4::date) + DATE(start_time) >= $1::date AND DATE(start_time) <= $2::date ) SELECT DATE(seasonPS.start_time), JSON_AGG(seasonPS.*) AS data FROM seasonPS GROUP BY DATE(start_time) ORDER BY DATE(start_time) ASC; `, - [startTime, endTime, secondstartTime, secondendTime], + [startTime, endTime], ); res.status(200).json(keysToCamel(seasonResult)); } catch (err) {