From fcf8a1432199586b5220c439e92280237c41d4f4 Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Mon, 4 Mar 2024 15:11:40 -0800 Subject: [PATCH 1/3] sort events by start time --- routes/publishedSchedule.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 0008790..b33a70d 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -198,6 +198,7 @@ publishedScheduleRouter.get('/season', async (req, res) => { WHERE D.event_date >= $1::date AND D.event_date <= $2::date AND D.id = PS.day_id + ORDER BY PS.start_time ASC ) SELECT event_date, json_build_object ( From 5d962dccfec200695e4feb358c51ae7f51e78108 Mon Sep 17 00:00:00 2001 From: ctc-devops <90984711+ctc-devops@users.noreply.github.com> Date: Mon, 4 Mar 2024 21:10:24 -0800 Subject: [PATCH 2/3] Added names to accounts (#55) * Create a pull trequest for branch 52-add-names-to-accounts * added first and last name to db and create user route --------- Co-authored-by: Cheryl Chen --- routes/users.js | 6 +++--- server/schema/users.sql | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/routes/users.js b/routes/users.js index 9f2b5cd..7f2ce2a 100644 --- a/routes/users.js +++ b/routes/users.js @@ -37,10 +37,10 @@ userRouter.get('/:uid', async (req, res) => { userRouter.post('/create', async (req, res) => { try { - const { id, email, type, approved, approvedOn } = req.body; + const { id, email, type, approved, approvedOn, firstName, lastName } = req.body; await db.query( - `INSERT INTO users (id, email, "type", approved, approved_on) VALUES ($1, $2, $3, $4, $5);`, - [id, email, type, approved, approvedOn], + `INSERT INTO users (id, email, "type", approved, approved_on, first_name, last_name) VALUES ($1, $2, $3, $4, $5, $6, $7);`, + [id, email, type, approved, approvedOn, firstName, lastName], ); res.status(201).json({ id, diff --git a/server/schema/users.sql b/server/schema/users.sql index 785246f..e45297a 100644 --- a/server/schema/users.sql +++ b/server/schema/users.sql @@ -8,4 +8,6 @@ CREATE TABLE users ( type account_type NOT NULL, approved BOOLEAN NOT NULL, approved_on DATE NOT NULL, + first_name VARCHAR(50) NOT NULL, + last_name VARCHAR(50) NOT NULL ); \ No newline at end of file From 475e3d97c22a20537cd691e496bc1930e94071ff Mon Sep 17 00:00:00 2001 From: Ethan Ho Date: Mon, 4 Mar 2024 21:31:33 -0800 Subject: [PATCH 3/3] Updated PS routes for ordering and schema for User table (#54) Co-authored-by: Maithy Le Co-authored-by: michellelin1 <66575725+michellelin1@users.noreply.github.com> --- common/utils.js | 24 +++++++++++++++++++++- routes/publishedSchedule.js | 41 ++++++++++++------------------------- server/schema/users.sql | 2 +- 3 files changed, 37 insertions(+), 30 deletions(-) diff --git a/common/utils.js b/common/utils.js index fb5f261..b39ec62 100644 --- a/common/utils.js +++ b/common/utils.js @@ -85,4 +85,26 @@ const keysToCamel = (data) => { return data; }; -module.exports = { keysToCamel, isInteger, calculateYear }; +const getSeasonFromMonthAndYear = (month, year) => { + if (month === 11) { + return `Winter ${year + 1}`; + } + if (month === 0 || month === 1) { + return `Winter ${year}`; + } + // spring + // march-may -> winter [year] + if (month >= 2 && month <= 4) { + return `Winter ${year}`; + } + // summer + // june-august -> summer [year] + if (month >= 5 && month <= 7) { + return `Summer ${year}`; + } + // fall + // september-november -> fall [year] + return `Fall ${year}`; +}; + +module.exports = { keysToCamel, isInteger, calculateYear, getSeasonFromMonthAndYear }; diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index b33a70d..a515f27 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -1,6 +1,6 @@ const express = require('express'); const { db } = require('../server/db'); -const { keysToCamel, calculateYear } = require('../common/utils'); +const { keysToCamel, calculateYear, getSeasonFromMonthAndYear } = require('../common/utils'); const publishedScheduleRouter = express.Router(); @@ -96,30 +96,7 @@ publishedScheduleRouter.get('/all-seasons', async (req, res) => { const formattedDate = new Date(date.event_date); const year = formattedDate.getFullYear(); const month = formattedDate.getMonth(); - // const day = formattedDate.getDate(); - - // winter - // december (11) -> winter [year + 1] - // january (0) - february (1) -> winter [year] - if (month === 11) { - return `Winter ${year + 1}`; - } - if (month === 0 || month === 1) { - return `Winter ${year}`; - } - // spring - // march-may -> winter [year] - if (month >= 2 && month <= 4) { - return `Winter ${year}`; - } - // summer - // june-august -> summer [year] - if (month >= 5 && month <= 7) { - return `Summer ${year}`; - } - // fall - // september-november -> fall [year] - return `Fall ${year}`; + return getSeasonFromMonthAndYear(month, year); }; try { @@ -130,12 +107,20 @@ publishedScheduleRouter.get('/all-seasons', async (req, res) => { published_schedule AS PS, day AS D WHERE D.id = PS.day_id + ORDER BY + D.event_date DESC; `, ); - const allSeasonsResult = allDatesResult.map((row) => { - return getSeason(row); + const allUniqueSeasonsResult = []; + + // Get all unique seasons by order of season, from most recent to least + allDatesResult.forEach((row) => { + const season = getSeason(row); + if (!allUniqueSeasonsResult.includes(season)) { + allUniqueSeasonsResult.push(season); + } }); - const allUniqueSeasonsResult = [...new Set(allSeasonsResult)]; + res.status(200).json(keysToCamel(allUniqueSeasonsResult)); } catch (err) { res.status(500).send(err.message); diff --git a/server/schema/users.sql b/server/schema/users.sql index e45297a..f9598e0 100644 --- a/server/schema/users.sql +++ b/server/schema/users.sql @@ -1,4 +1,4 @@ -CREATE TYPE account_type as ENUM ('superadmin', 'admin'); +CREATE TYPE account_type as ENUM ('admin', 'student'); DROP TABLE IF EXISTS users;