From b1bc220d0d945139ffa02c5f43d0eba5306957ee Mon Sep 17 00:00:00 2001 From: Alyssia Tan Date: Thu, 8 Feb 2024 16:09:27 -0800 Subject: [PATCH 1/6] completed table, post, and put changes for users table --- routes/users.js | 18 ++++++++---------- server/schema/users.sql | 3 ++- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/routes/users.js b/routes/users.js index 6f26153..9f2b5cd 100644 --- a/routes/users.js +++ b/routes/users.js @@ -37,18 +37,15 @@ userRouter.get('/:uid', async (req, res) => { userRouter.post('/create', async (req, res) => { try { - const { id, email, type, approved } = req.body; - await db.query(`INSERT INTO users (id, email, "type", approved) VALUES ($1, $2, $3, $4);`, [ - id, - email, - type, - approved, - ]); + const { id, email, type, approved, approvedOn } = 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], + ); res.status(201).json({ id, }); } catch (err) { - console.log('err', err); res.status(500).json({ status: 'Failed', msg: err.message, @@ -59,9 +56,10 @@ userRouter.post('/create', async (req, res) => { userRouter.put('/approve/:uid', async (req, res) => { try { const { uid } = req.params; + const currDate = new Date(); const updatedApproval = await db.query( - `UPDATE users SET approved = TRUE WHERE id = $1 RETURNING *;`, - [uid], + `UPDATE users SET approved = TRUE, approved_on = $1 WHERE id = $2 RETURNING *;`, + [currDate, uid], ); return res.status(200).send(keysToCamel(updatedApproval)); } catch (err) { diff --git a/server/schema/users.sql b/server/schema/users.sql index b652586..785246f 100644 --- a/server/schema/users.sql +++ b/server/schema/users.sql @@ -6,5 +6,6 @@ CREATE TABLE users ( id VARCHAR ( 256 ) PRIMARY KEY, email VARCHAR ( 50 ) NOT NULL, type account_type NOT NULL, - approved BOOLEAN NOT NULL + approved BOOLEAN NOT NULL, + approved_on DATE NOT NULL, ); \ No newline at end of file From f983b847160c415d8a9d91c9564a917b8da42f39 Mon Sep 17 00:00:00 2001 From: Alyssia Tan Date: Sat, 17 Feb 2024 15:55:01 -0800 Subject: [PATCH 2/6] changed and added published sched routes --- routes/publishedSchedule.js | 90 ++++++++++++++++++++++++---- server/schema/published_schedule.sql | 1 + 2 files changed, 79 insertions(+), 12 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 43c8376..5bebc45 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -18,7 +18,8 @@ publishedScheduleRouter.get('/', async (req, res) => { PS.start_time, PS.end_time, PS.cohort, - PS.notes + PS.notes, + PS.created_on FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id; @@ -30,6 +31,64 @@ publishedScheduleRouter.get('/', async (req, res) => { } }); +// GET/published-schedule/recently-added - returns the rows that were added in the past week +publishedScheduleRouter.get('/recently-added', async (req, res) => { + try { + const recentAddResult = await db.query( + ` + SELECT + PS.id, + C.title, + C.event_type, + C.year, + PS.start_time, + PS.end_time, + PS.confirmed, + PS.confirmed_on, + PS.cohort, + PS.notes, + PS.created_on + FROM published_schedule PS + LEFT JOIN catalog C ON PS.event_id = C.id + WHERE PS.created_on > current_date - 7 + ORDER BY created_on DESC; + `, + ); + res.status(200).json(keysToCamel(recentAddResult)); + } catch (err) { + res.status(400).send(err.message); + } +}); + +// GET/published-schedule/recently-confirmed - returns the rows that were confirmed in the past week +publishedScheduleRouter.get('/recently-confirmed', async (req, res) => { + try { + const recentConfirm = await db.query( + ` + SELECT + PS.id, + C.title, + C.event_type, + C.year, + PS.start_time, + PS.end_time, + PS.confirmed, + PS.confirmed_on, + PS.cohort, + PS.notes, + PS.created_on + FROM published_schedule PS + LEFT JOIN catalog C ON PS.event_id = C.id + WHERE PS.confirmed_on > current_date - 7 + ORDER BY created_on DESC; + `, + ); + res.status(200).json(keysToCamel(recentConfirm)); + } catch (err) { + res.status(400).send(err.message); + } +}); + // GET /published-schedule/season - returns rows that match the season publishedScheduleRouter.get('/season', async (req, res) => { try { @@ -67,7 +126,8 @@ publishedScheduleRouter.get('/season', async (req, res) => { PS.confirmed, PS.confirmed_on, PS.cohort, - PS.notes + PS.notes, + PS.created_on FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id WHERE @@ -102,7 +162,8 @@ publishedScheduleRouter.get('/date', async (req, res) => { PS.confirmed, PS.confirmed_on, PS.cohort, - PS.notes + PS.notes, + PS.created_on FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id WHERE DATE(PS.start_time) = $1 @@ -131,7 +192,8 @@ publishedScheduleRouter.get('/:id', async (req, res) => { PS.start_time, PS.end_time, PS.cohort, - PS.notes + PS.notes, + PS.created_on FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id @@ -148,6 +210,7 @@ publishedScheduleRouter.get('/:id', async (req, res) => { // POST - Adds a new row to the published_schedule table publishedScheduleRouter.post('/', async (req, res) => { const { eventId, confirmed, confirmedOn, startTime, endTime, cohort, notes } = req.body; + const currDate = new Date(); try { const returnedData = await db.query( ` @@ -160,13 +223,14 @@ publishedScheduleRouter.post('/', async (req, res) => { start_time, end_time, cohort, - notes + notes, + created_on ) VALUES - (nextval('published_schedule_id_seq'), $1, $2, $3, $4, $5, $6, $7) - RETURNING id; + (nextval('published_schedule_id_seq'), $1, $2, $3, $4, $5, $6, $7, $8) + RETURNING id, created_on; `, - [eventId, confirmed, confirmedOn, startTime, endTime, cohort, notes], + [eventId, confirmed, confirmedOn, startTime, endTime, cohort, notes, currDate], ); res.status(201).json({ status: 'Success', @@ -181,7 +245,8 @@ publishedScheduleRouter.post('/', async (req, res) => { publishedScheduleRouter.put('/:id', async (req, res) => { try { const { id } = req.params; - const { eventId, confirmed, confirmedOn, startTime, endTime, cohort, notes } = req.body; + const { eventId, confirmed, confirmedOn, startTime, endTime, cohort, notes, createdOn } = + req.body; const updatedPublishedSchedule = await db.query( ` UPDATE published_schedule @@ -192,12 +257,13 @@ publishedScheduleRouter.put('/:id', async (req, res) => { start_time = COALESCE($4, start_time), end_time = COALESCE($5, end_time), cohort = COALESCE($6, cohort), - notes = COALESCE($7, notes) - WHERE id = $8 + notes = COALESCE($7, notes), + created_on = COALESCE($8, created_on) + WHERE id = $9 RETURNING *; `, - [eventId, confirmed, confirmedOn, startTime, endTime, cohort, notes, id], + [eventId, confirmed, confirmedOn, startTime, endTime, cohort, notes, createdOn, id], ); res.status(200).json(keysToCamel(updatedPublishedSchedule)); } catch (err) { diff --git a/server/schema/published_schedule.sql b/server/schema/published_schedule.sql index 7d04a9e..484573c 100644 --- a/server/schema/published_schedule.sql +++ b/server/schema/published_schedule.sql @@ -8,6 +8,7 @@ CREATE TABLE IF NOT EXISTS published_schedule ( end_time timestamp NOT NULL, cohort varchar[] NOT NULL, notes varchar(100), + created_on date NOT NULL, FOREIGN KEY (event_id) REFERENCES catalog (id) ); From 861c99a2be3d335b8a958092c8fcdd49b29845a7 Mon Sep 17 00:00:00 2001 From: Alyssia Tan Date: Sat, 17 Feb 2024 16:02:16 -0800 Subject: [PATCH 3/6] recently-added returns events with equivalent confirm and create dates --- routes/publishedSchedule.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 5bebc45..f6ba9e5 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -50,7 +50,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 > current_date - 7 + WHERE PS.created_on = PS.confirmed_on AND PS.created_on > current_date - 7 AND confirmed = true ORDER BY created_on DESC; `, ); From 7f5ea0a1115d090e68053ed316f0bfa2f82d1085 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Sun, 18 Feb 2024 06:38:31 +0000 Subject: [PATCH 4/6] Fix swapped conditions for confirmed and added events --- routes/publishedSchedule.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index f6ba9e5..7182884 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -50,7 +50,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.confirmed_on > current_date - 7 ORDER BY created_on DESC; `, ); @@ -79,7 +79,7 @@ publishedScheduleRouter.get('/recently-confirmed', async (req, res) => { PS.created_on FROM published_schedule PS LEFT JOIN catalog C ON PS.event_id = C.id - WHERE PS.confirmed_on > current_date - 7 + WHERE PS.created_on = PS.confirmed_on AND PS.created_on > current_date - 7 AND confirmed = true ORDER BY created_on DESC; `, ); From 00ecd80ba935aa0df17ff2d918302af02d9cb934 Mon Sep 17 00:00:00 2001 From: Sean Fong Date: Sun, 18 Feb 2024 07:01:30 +0000 Subject: [PATCH 5/6] Revert previous condition change --- routes/publishedSchedule.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 7182884..f6ba9e5 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -50,7 +50,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.confirmed_on > current_date - 7 + WHERE PS.created_on = PS.confirmed_on AND PS.created_on > current_date - 7 AND confirmed = true ORDER BY created_on DESC; `, ); @@ -79,7 +79,7 @@ publishedScheduleRouter.get('/recently-confirmed', 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.confirmed_on > current_date - 7 ORDER BY created_on DESC; `, ); From 2bd47cd71cb2a8d598ce962bf9b59356bd05955c Mon Sep 17 00:00:00 2001 From: ThatMegamind Date: Tue, 20 Feb 2024 15:36:45 -0800 Subject: [PATCH 6/6] minor fixes post-merge --- routes/publishedSchedule.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 6956d29..0008790 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -87,6 +87,8 @@ publishedScheduleRouter.get('/recently-confirmed', async (req, res) => { res.status(200).json(keysToCamel(recentConfirm)); } catch (err) { res.status(400).send(err.message); + } +}); // GET /published-schedule/all-seasons - return all the seasons publishedScheduleRouter.get('/all-seasons', async (req, res) => { @@ -123,10 +125,10 @@ publishedScheduleRouter.get('/all-seasons', async (req, res) => { try { const allDatesResult = await db.query( ` - SELECT D.event_date + SELECT D.event_date FROM published_schedule AS PS, day AS D - WHERE + WHERE D.id = PS.day_id `, ); @@ -357,7 +359,7 @@ publishedScheduleRouter.post('/', async (req, res) => { endTime, calculateYear(eventDate, cohort), notes, - currDate + currDate, ], ); res.status(201).json({ @@ -408,7 +410,7 @@ publishedScheduleRouter.put('/:id', async (req, res) => { cohort = COALESCE($7, cohort), notes = COALESCE($8, notes) created_on = COALESCE($9, created_on) - + WHERE id = $10 RETURNING *;