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/routes/users.js b/routes/users.js index 9e1c50f..3fc3702 100644 --- a/routes/users.js +++ b/routes/users.js @@ -38,7 +38,6 @@ userRouter.get('/pending-accounts', async (req, res) => { userRouter.post('/create', async (req, res) => { try { const { id, email, type, approved } = req.body; - // console.log('req.body', req.body); await db.query(`INSERT INTO users (id, email, "type", approved) VALUES ($1, $2, $3, $4);`, [ id, email, 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) );