diff --git a/routes/catalog.js b/routes/catalog.js index fa067f8..e286012 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -96,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, hidden) - VALUES (nextval('catalog_id_seq'), $1, $2, $3, $4, $5, $6, $7, $8, false) + `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) { @@ -118,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 *;`, @@ -141,7 +140,6 @@ catalogRouter.put('/:id', async (req, res) => { description, year, id, - location, season, }, ); diff --git a/server/schema/catalog.sql b/server/schema/catalog.sql index 7302266..e32df3e 100644 --- a/server/schema/catalog.sql +++ b/server/schema/catalog.sql @@ -8,11 +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 );