From b23ac6158156ac8217d8f326519e2123d891ef40 Mon Sep 17 00:00:00 2001 From: ThatMegamind <92563733+ThatMegamind@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:07:28 -0700 Subject: [PATCH 1/3] 56 bug batch 1 (#62) * /season route now returns event id * missing comma --------- Co-authored-by: Alyssia Tan --- routes/publishedSchedule.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/routes/publishedSchedule.js b/routes/publishedSchedule.js index a515f27..2e85ecb 100644 --- a/routes/publishedSchedule.js +++ b/routes/publishedSchedule.js @@ -160,6 +160,7 @@ publishedScheduleRouter.get('/season', async (req, res) => { ( SELECT PS.id, + PS.event_id, PS.day_id, D.id AS day_day_id, D.event_date, @@ -197,6 +198,7 @@ publishedScheduleRouter.get('/season', async (req, res) => { JSON_AGG( json_build_object ( 'id', seasonPS.id, + 'event_id', seasonPS.event_id, 'title', seasonPS.title, 'event_type', seasonPS.event_type, 'year', seasonPS.year, @@ -394,7 +396,7 @@ publishedScheduleRouter.put('/:id', async (req, res) => { start_time = COALESCE($5, start_time), end_time = COALESCE($6, end_time), cohort = COALESCE($7, cohort), - notes = COALESCE($8, notes) + notes = COALESCE($8, notes), created_on = COALESCE($9, created_on) WHERE id = $10 From d49e349ccbfbd6f36fdbe4e7263989cb755e35ff Mon Sep 17 00:00:00 2001 From: cherhchen <54284307+cherhchen@users.noreply.github.com> Date: Thu, 21 Mar 2024 15:26:57 -0700 Subject: [PATCH 2/3] added approved-accounts route (#59) Co-authored-by: Cheryl Chen Co-authored-by: ThatMegamind <92563733+ThatMegamind@users.noreply.github.com> --- routes/users.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/routes/users.js b/routes/users.js index 7f2ce2a..707a026 100644 --- a/routes/users.js +++ b/routes/users.js @@ -17,7 +17,20 @@ userRouter.get('/', async (req, res) => { userRouter.get('/pending-accounts', async (req, res) => { try { - const pendingAccounts = await db.query(`SELECT * FROM users WHERE approved = FALSE;`); + const pendingAccounts = await db.query( + `SELECT * FROM users WHERE approved = FALSE ORDER BY first_name ASC;`, + ); + res.status(200).json(keysToCamel(pendingAccounts)); + } catch (err) { + res.status(500).send(err.message); + } +}); + +userRouter.get('/approved-accounts', async (req, res) => { + try { + const pendingAccounts = await db.query( + `SELECT * FROM users WHERE approved = TRUE ORDER BY first_name ASC;`, + ); res.status(200).json(keysToCamel(pendingAccounts)); } catch (err) { res.status(500).send(err.message); From b5327bf5284161fcff185e4c1a87628453c77fff Mon Sep 17 00:00:00 2001 From: Ethan Ho Date: Thu, 21 Mar 2024 15:31:33 -0700 Subject: [PATCH 3/3] 58 bug batch 2 backend (#61) * Implemented event deletion, updated schemas/databases. Minor bugfixes. * Bugfixes: Added comma * updated catalog schema * fixed schema (for realsies this time) and updated some sql queries because db changed --- common/utils.js | 2 +- routes/catalog.js | 36 ++++++++++++++++------------ server/schema/catalog.sql | 6 ++--- server/schema/day.sql | 5 ++-- server/schema/published_schedule.sql | 2 +- 5 files changed, 29 insertions(+), 22 deletions(-) diff --git a/common/utils.js b/common/utils.js index b39ec62..ba67f5e 100644 --- a/common/utils.js +++ b/common/utils.js @@ -27,7 +27,7 @@ const isInteger = (value) => { // dependency for publishedSchedule.js const calculateYear = (eventDate, gradeLevel) => { - if (gradeLevel) { + if (gradeLevel && gradeLevel.length) { const currentDay = new Date(eventDate); // console.log('current day', currentDay.getFullYear() + (currentDay.getMonth() >= 7 ? 2 : 1)); if (gradeLevel.toLowerCase() === 'junior') { diff --git a/routes/catalog.js b/routes/catalog.js index f3c18a5..e286012 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -15,7 +15,7 @@ catalogRouter.get('/', async (req, res) => { const offset = (page - 1) * limit; - let query = 'FROM catalog WHERE 1=1'; + let query = 'FROM catalog WHERE 1=1 AND hidden = false'; // removed space at beginning here const params = []; @@ -85,7 +85,9 @@ catalogRouter.get('/', async (req, res) => { catalogRouter.get('/:id', async (req, res) => { try { const { id } = req.params; - const allUsers = await db.query(`SELECT * FROM catalog WHERE id = $1;`, [id]); + const allUsers = await db.query(`SELECT * FROM catalog WHERE id = $1 AND hidden = false;`, [ + id, + ]); res.status(200).json(keysToCamel(allUsers)); } catch (err) { res.status(500).send(err.message); @@ -94,13 +96,13 @@ catalogRouter.get('/:id', async (req, res) => { // -- POST - Adds a new row to the catalog table catalogRouter.post('/', async (req, res) => { - const { host, title, eventType, subject, description, year, season, location } = req.body; + const { host, title, eventType, subject, description, year, season } = req.body; try { const returnedData = await db.query( - `INSERT INTO catalog (id, host, title, event_type, subject, description, year, season, location) - VALUES (nextval('catalog_id_seq'), $1, $2, $3, $4, $5, $6, $7, $8) + `INSERT INTO catalog (id, host, title, event_type, subject, description, year, season, hidden) + VALUES (nextval('catalog_id_seq'), $1, $2, $3::event[], $4::subject[], $5, $6::year[], $7::season[], false) RETURNING id;`, - [host, title, eventType, subject, description, year, season, location], + [host, title, eventType, subject, description, year, season], ); res.status(201).json({ id: returnedData[0].id, status: 'Success' }); } catch (err) { @@ -116,18 +118,17 @@ catalogRouter.post('/', async (req, res) => { catalogRouter.put('/:id', async (req, res) => { try { const { id } = req.params; - const { host, title, eventType, subject, description, year, location, season } = req.body; + const { host, title, eventType, subject, description, year, season } = req.body; const updatedCatalog = await db.query( `UPDATE catalog SET ${host ? 'host = $(host), ' : ''} ${title ? 'title = $(title),' : ''} - ${eventType ? 'event_type = $(eventType), ' : ''} - ${subject ? 'subject = $(subject), ' : ''} + ${eventType ? 'event_type = $(eventType)::event[], ' : ''} + ${subject ? 'subject = $(subject)::subject[], ' : ''} ${description ? 'description = $(description), ' : ''} - ${year ? 'year = $(year), ' : ''} - ${location ? 'location = $(location), ' : ''} - ${season ? 'season = $(season), ' : ''} + ${year ? 'year = $(year)::year[], ' : ''} + ${season ? 'season = $(season)::season[], ' : ''} id = '${id}' WHERE id = '${id}' RETURNING *;`, @@ -139,7 +140,6 @@ catalogRouter.put('/:id', async (req, res) => { description, year, id, - location, season, }, ); @@ -153,8 +153,14 @@ catalogRouter.put('/:id', async (req, res) => { catalogRouter.delete('/:id', async (req, res) => { try { const { id } = req.params; - const delUser = await db.query(`DELETE FROM catalog WHERE id = $1 RETURNING *;`, [id]); - res.status(200).send(keysToCamel(delUser)); + const inUse = await db.query(`SELECT * FROM published_schedule WHERE event_id = $1;`, [id]); + let hidden; + if (inUse && inUse.length) { + hidden = await db.query(`UPDATE catalog SET hidden = true WHERE id = $1 RETURNING *;`, [id]); + } else { + hidden = await db.query(`DELETE FROM catalog WHERE id = $1 RETURNING *;`, [id]); + } + res.status(200).send(keysToCamel(hidden)); } catch (err) { res.status(500).send(err.message); } diff --git a/server/schema/catalog.sql b/server/schema/catalog.sql index c3096a2..e32df3e 100644 --- a/server/schema/catalog.sql +++ b/server/schema/catalog.sql @@ -8,10 +8,10 @@ CREATE TABLE catalog ( id SERIAL PRIMARY KEY, host VARCHAR(50) NOT NULL, title VARCHAR(50) NOT NULL, - event_type event NOT NULL, - subject subject NOT NULL, + event_type event[] NOT NULL, + subject subject[] NOT NULL, description VARCHAR(50) NOT NULL, year year NOT NULL, season season, - location VARCHAR(256) + hidden boolean NOT NULL ); diff --git a/server/schema/day.sql b/server/schema/day.sql index 1ac0b41..c29f5d2 100644 --- a/server/schema/day.sql +++ b/server/schema/day.sql @@ -1,9 +1,10 @@ DROP TABLE IF EXISTS day; CREATE TABLE IF NOT EXISTS day ( id serial PRIMARY KEY, - event_date DATE NOT NULL, + event_date DATE UNIQUE NOT NULL, start_time TIME NOT NULL, end_time TIME NOT NULL, location VARCHAR( 256 ) NOT NULL, - notes VARCHAR( 250 ) + notes VARCHAR( 250 ), + day_count INTEGER ); \ No newline at end of file diff --git a/server/schema/published_schedule.sql b/server/schema/published_schedule.sql index 90e6fe7..ee3feee 100644 --- a/server/schema/published_schedule.sql +++ b/server/schema/published_schedule.sql @@ -13,7 +13,7 @@ CREATE TABLE IF NOT EXISTS published_schedule ( FOREIGN KEY (event_id) REFERENCES catalog (id), FOREIGN KEY (day_id) - REFERENCES day (id) + REFERENCES day (id) ON DELETE CASCADE ); CREATE INDEX idx_day_id ON published_schedule (day_id); \ No newline at end of file