Skip to content

Commit

Permalink
mapped season to month
Browse files Browse the repository at this point in the history
  • Loading branch information
Cheryl Chen committed Feb 2, 2024
1 parent 4e0682e commit 1cc91b6
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions routes/publishedSchedule.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,38 @@ 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`;
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(
`
WITH seasonPS AS
Expand All @@ -52,15 +83,15 @@ publishedScheduleRouter.get('/season', async (req, res) => {
FROM published_schedule PS
LEFT JOIN catalog C ON PS.event_id = C.id
WHERE
C.season = $1 AND
EXTRACT(YEAR FROM PS.start_time) = $2
(DATE(start_time) >= $1::date AND DATE(start_time) <= $2::date) OR
(DATE(start_time) >= $3::date AND DATE(start_time) <= $4::date)
)
SELECT DATE(seasonPS.start_time), JSON_AGG(seasonPS.*) AS data
FROM seasonPS
GROUP BY DATE(start_time)
ORDER BY DATE(start_time) ASC;
`,
[season, year],
[startTime, endTime, secondstartTime, secondendTime],
);
res.status(200).json(keysToCamel(seasonResult));
} catch (err) {
Expand Down

0 comments on commit 1cc91b6

Please sign in to comment.