From 1bd80e65579656fb7a8760da091e5229b862f635 Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Tue, 30 Apr 2024 23:49:37 -0700 Subject: [PATCH 1/2] made ps.confirmed_on optional --- routes/publishedSchedule.js | 6 +++--- server/schema/published_schedule.sql | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 749be96..5747bff 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -51,7 +51,7 @@ publishedScheduleRouter.get('/recently-added', async (req, res) => { PS.created_on FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id - WHERE PS.created_on = PS.confirmed_on AND PS.created_on > current_date - 7 AND confirmed = true + WHERE PS.created_on > current_date - 7 AND confirmed = true ORDER BY created_on DESC; `, ); @@ -237,7 +237,7 @@ publishedScheduleRouter.get('/stats', async (req, res) => { FROM all_event_types aet CROSS JOIN all_subjects asu ) - SELECT + SELECT COALESCE(ap.event_type::text, 'Total') AS event_type, COALESCE(ap.subject::text, 'Total') AS subject, COALESCE(COUNT(c.catalog_id), 0) AS total_count @@ -406,7 +406,7 @@ publishedScheduleRouter.post('/', async (req, res) => { eventId, dayId, confirmed, - new Date(), + null, startTime, endTime, calculateYear(eventDate, cohort), diff --git a/server/schema/published_schedule.sql b/server/schema/published_schedule.sql index ee3feee..a00a378 100644 --- a/server/schema/published_schedule.sql +++ b/server/schema/published_schedule.sql @@ -4,7 +4,7 @@ CREATE TABLE IF NOT EXISTS published_schedule ( event_id integer NOT NULL, day_id integer NOT NULL, confirmed boolean NOT NULL, - confirmed_on date NOT NULL, + confirmed_on date, start_time time NOT NULL, end_time time NOT NULL, cohort varchar[] NOT NULL, @@ -16,4 +16,4 @@ CREATE TABLE IF NOT EXISTS published_schedule ( REFERENCES day (id) ON DELETE CASCADE ); -CREATE INDEX idx_day_id ON published_schedule (day_id); \ No newline at end of file +CREATE INDEX idx_day_id ON published_schedule (day_id); From 4554450c1f40112c6063700169cc1933f9399d15 Mon Sep 17 00:00:00 2001 From: ThatMegamind Date: Wed, 1 May 2024 12:32:55 -0700 Subject: [PATCH 2/2] fixed season retrieval for stat modal --- common/utils.js | 18 +++++++++++++++++- routes/publishedSchedule.js | 15 +++++++++++---- 2 files changed, 28 insertions(+), 5 deletions(-) diff --git a/common/utils.js b/common/utils.js index 2ba4fef..76a57a4 100644 --- a/common/utils.js +++ b/common/utils.js @@ -110,4 +110,20 @@ const getSeasonFromMonthAndYear = (month, year) => { return `Fall ${year}`; }; -module.exports = { keysToCamel, isInteger, calculateYear, getSeasonFromMonthAndYear }; +const getMonthRangeFromSeason = (season) => { + if (season === 'spring') { + return [0, 4]; + } + if (season === 'summer') { + return [5, 7]; + } + return [8, 12]; +}; + +module.exports = { + keysToCamel, + isInteger, + calculateYear, + getSeasonFromMonthAndYear, + getMonthRangeFromSeason, +}; diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 5747bff..a0ba8f3 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -1,6 +1,11 @@ const express = require('express'); const { db } = require('../server/db'); -const { keysToCamel, calculateYear, getSeasonFromMonthAndYear } = require('../common/utils'); +const { + keysToCamel, + calculateYear, + getSeasonFromMonthAndYear, + getMonthRangeFromSeason, +} = require('../common/utils'); const publishedScheduleRouter = express.Router(); @@ -221,6 +226,7 @@ publishedScheduleRouter.get('/season', async (req, res) => { publishedScheduleRouter.get('/stats', async (req, res) => { try { const { season, year } = req.query; + const [monthStart, monthEnd] = getMonthRangeFromSeason(season); const statResult = await db.query( ` @@ -249,8 +255,9 @@ publishedScheduleRouter.get('/stats', async (req, res) => { FROM catalog c JOIN published_schedule ps ON c.id = ps.event_id JOIN day d ON PS.day_id = d.id - WHERE $1 = ANY(c.season) - AND EXTRACT(YEAR FROM d.event_date) = $2 + WHERE EXTRACT(MONTH FROM d.event_date) >= $1 + AND EXTRACT(MONTH FROM d.event_date) <= $2 + AND EXTRACT(YEAR FROM d.event_date) = $3 ) c ON ap.event_type = ANY(c.event_type) AND ap.subject = ANY(c.subject) GROUP BY ROLLUP (ap.event_type), ROLLUP (ap.subject) ORDER BY CASE WHEN ap.event_type IS NULL THEN 1 ELSE 0 END, @@ -258,7 +265,7 @@ publishedScheduleRouter.get('/stats', async (req, res) => { ap.event_type NULLS FIRST, ap.subject NULLS FIRST; `, - [season, year], + [monthStart, monthEnd, year], ); res.status(200).json(keysToCamel(statResult));