From 3ef8a11c837626eb3c6d2eb3d5acee0e523965a3 Mon Sep 17 00:00:00 2001 From: michellelin1 <66575725+michellelin1@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:56:07 -0800 Subject: [PATCH] updated catalog schema + routes --- routes/catalog.js | 14 +++++++++----- server/schema/catalog.sql | 5 ++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/routes/catalog.js b/routes/catalog.js index eac9d18..6d914b2 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -28,13 +28,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 } = req.body; + const { host, title, eventType, subject, description, year, season, location } = req.body; try { const returnedData = await db.query( - `INSERT INTO catalog (id, host, title, event_type, subject, description, year) - VALUES (nextval('catalog_id_seq'), $1, $2, $3, $4, $5, $6) + `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) RETURNING id;`, - [host, title, eventType, subject, description, year], + [host, title, eventType, subject, description, year, season, location], ); res.status(201).json({ id: returnedData[0].id, status: 'Success' }); } catch (err) { @@ -50,7 +50,7 @@ catalogRouter.post('/', async (req, res) => { catalogRouter.put('/:id', async (req, res) => { try { const { id } = req.params; - const { host, title, eventType, subject, description, year } = req.body; + const { host, title, eventType, subject, description, year, location, season } = req.body; const updatedCatalog = await db.query( `UPDATE catalog SET @@ -60,6 +60,8 @@ catalogRouter.put('/:id', async (req, res) => { ${subject ? 'subject = $(subject), ' : ''} ${description ? 'description = $(description), ' : ''} ${year ? 'year = $(year), ' : ''} + ${location ? 'location = $(location), ' : ''} + ${season ? 'season = $(season), ' : ''} id = '${id}' WHERE id = '${id}' RETURNING *;`, @@ -71,6 +73,8 @@ catalogRouter.put('/:id', async (req, res) => { description, year, id, + location, + season, }, ); res.status(200).send(keysToCamel(updatedCatalog)); diff --git a/server/schema/catalog.sql b/server/schema/catalog.sql index d49128c..c3096a2 100644 --- a/server/schema/catalog.sql +++ b/server/schema/catalog.sql @@ -1,6 +1,7 @@ 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 season AS ENUM ('spring', 'summer', 'fall', 'winter'); DROP TABLE IF EXISTS catalog; CREATE TABLE catalog ( @@ -10,5 +11,7 @@ CREATE TABLE catalog ( event_type event NOT NULL, subject subject NOT NULL, description VARCHAR(50) NOT NULL, - year year NOT NULL + year year NOT NULL, + season season, + location VARCHAR(256) );