From dce0353060e7ae0c9e3a58f28a32193bfb3bc8ad Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Fri, 19 Apr 2024 21:30:00 -0700 Subject: [PATCH 1/4] fix existing day issue --- routes/day.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/routes/day.js b/routes/day.js index faf7762..9f9b469 100644 --- a/routes/day.js +++ b/routes/day.js @@ -40,12 +40,25 @@ dayRouter.get('/:id', async (req, res) => { dayRouter.post('/', async (req, res) => { try { const { eventDate, location, notes } = req.body; - const inUse = await db.query(`SELECT * FROM day WHERE event_date = $1;`, [eventDate]); - if (inUse.length) { - res.status(201).json({ - status: 'Failed', - message: 'Day already exists', - }); + const existingDay = await db.query(`SELECT * FROM day WHERE event_date = $1;`, [eventDate]); + if (existingDay.length) { + // day exists but has no events --> update location + notes return existing day_id + if (existingDay[0].day_count === 0) { + await db.query(`UPDATE day SET location = $1, notes = $2 WHERE id = $3;`, [ + location, + notes, + existingDay[0].id, + ]); + res.status(201).json({ + status: 'Success', + id: existingDay[0].id, + }); + } else { + res.status(201).json({ + status: 'Failed', + message: 'Day already exists', + }); + } return; } From 4cf2528d58c5a27202ef96c0a9638713d3a3b6df Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Wed, 24 Apr 2024 18:15:08 -0700 Subject: [PATCH 2/4] added year to return with ps --- routes/publishedSchedule.js | 1 + 1 file changed, 1 insertion(+) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index 30aa1af..b2c8955 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -165,6 +165,7 @@ publishedScheduleRouter.get('/season', async (req, res) => { C.event_type, C.year, C.description, + C.year, PS.start_time, PS.end_time, PS.confirmed, From 5ea6f6bf235d45196e681ecc806db59991d0ab09 Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Wed, 24 Apr 2024 18:15:59 -0700 Subject: [PATCH 3/4] removed both option --- server/schema/catalog.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/schema/catalog.sql b/server/schema/catalog.sql index 31b97a4..06544ad 100644 --- a/server/schema/catalog.sql +++ b/server/schema/catalog.sql @@ -1,6 +1,6 @@ CREATE TYPE event AS ENUM ('guest speaker', 'study-trip', 'workshop', 'other'); CREATE TYPE subject AS ENUM ('life skills', 'science', 'technology', 'engineering', 'math', 'college readiness'); -CREATE TYPE year AS ENUM ('junior', 'senior', 'both'); +CREATE TYPE year AS ENUM ('junior', 'senior'); CREATE TYPE season AS ENUM ('spring', 'summer', 'fall'); DROP TABLE IF EXISTS catalog; From 53831037881a6a6792f4c1d66c1469f3db0107d5 Mon Sep 17 00:00:00 2001 From: ThatMegamind Date: Thu, 25 Apr 2024 23:07:37 -0700 Subject: [PATCH 4/4] removed redundant addition of C.year --- routes/publishedSchedule.js | 1 - 1 file changed, 1 deletion(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index b2c8955..30aa1af 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -165,7 +165,6 @@ publishedScheduleRouter.get('/season', async (req, res) => { C.event_type, C.year, C.description, - C.year, PS.start_time, PS.end_time, PS.confirmed,