From 2087426464d72543a55d270ac3a6a10bed7f507a Mon Sep 17 00:00:00 2001 From: ctc-devops <90984711+ctc-devops@users.noreply.github.com> Date: Mon, 11 Mar 2024 13:21:15 -0700 Subject: [PATCH 1/5] Create a pull trequest for branch 57-catalog-create-event-form-backend From e0784e93a3ae8e526bd42ddd084ec375efdb2d71 Mon Sep 17 00:00:00 2001 From: Lana Ramadan Date: Wed, 20 Mar 2024 16:36:21 -0700 Subject: [PATCH 2/5] accommodating for the multi select fields in the catalog form --- routes/catalog.js | 5 +++-- server/schema/catalog.sql | 11 ++++++----- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/routes/catalog.js b/routes/catalog.js index f3c18a5..98a5a35 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -95,10 +95,11 @@ 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; + 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, location, hidden) + VALUES (nextval('catalog_id_seq'), $1, $2, $3::event[], $4::subject[], $5, $6::year[], $7::season[], $8, false) RETURNING id;`, [host, title, eventType, subject, description, year, season, location], ); diff --git a/server/schema/catalog.sql b/server/schema/catalog.sql index c3096a2..2a3b598 100644 --- a/server/schema/catalog.sql +++ b/server/schema/catalog.sql @@ -8,10 +8,11 @@ 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) + year year[] NOT NULL, + season season[], + location VARCHAR(256), + hidden BOOLEAN NOT NULL, ); From f9f1c91536b587d1aec51d43ece1a3d8b0f32b5f Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Thu, 21 Mar 2024 15:25:29 -0700 Subject: [PATCH 3/5] updated get request filters --- routes/catalog.js | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/routes/catalog.js b/routes/catalog.js index 98a5a35..eb4ca10 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -29,15 +29,7 @@ catalogRouter.get('/', async (req, res) => { if (subject) { const array = subject.split(','); - query += ' AND subject = ANY($2::subject[])'; - // for (let i = 0; i < array.length; i += 1) { - // query += `'${array[i]}'`; - // if (i < array.length - 1) { - // query += ', '; - // } - // } - // query += ')'; - // query += ' AND subject = $2'; + query += ' AND subject && $2::subject[]'; params.push(array); } else { params.push(''); @@ -45,7 +37,7 @@ catalogRouter.get('/', async (req, res) => { if (eventType) { const array = eventType.split(','); - query += ' AND event_type = ANY($3::event[])'; + query += ' AND event_type && $3::event[]'; params.push(array); } else { params.push(''); @@ -53,7 +45,7 @@ catalogRouter.get('/', async (req, res) => { if (season) { const array = season.split(','); - query += ' AND season = ANY($4::season[])'; + query += ' AND season && $4::season[]'; params.push(array); } else { params.push(''); @@ -61,7 +53,7 @@ catalogRouter.get('/', async (req, res) => { if (year) { const array = year.split(','); - query += ' AND year = ANY($5::year[])'; + query += ' AND year && $5::year[]'; params.push(array); } else { params.push(''); From 18afe5af55ea0118bda0023145301c071e69b687 Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Sat, 23 Mar 2024 15:30:28 -0700 Subject: [PATCH 4/5] update catalog scheme + removed location from post req --- routes/catalog.js | 8 ++++---- server/schema/catalog.sql | 13 ++++++------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/routes/catalog.js b/routes/catalog.js index eb4ca10..d7ef126 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -86,14 +86,14 @@ 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::event[], $4::subject[], $5, $6::year[], $7::season[], $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) { diff --git a/server/schema/catalog.sql b/server/schema/catalog.sql index 2a3b598..dcd12a9 100644 --- a/server/schema/catalog.sql +++ b/server/schema/catalog.sql @@ -6,13 +6,12 @@ CREATE TYPE season AS ENUM ('spring', 'summer', 'fall', 'winter'); DROP TABLE IF EXISTS catalog; CREATE TABLE catalog ( id SERIAL PRIMARY KEY, - host VARCHAR(50) NOT NULL, + host VARCHAR(50), title VARCHAR(50) 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), + event_type event[] DEFAULT '{}', + subject subject[] DEFAULT '{}', + description VARCHAR(100), + year year[] DEFAULT '{}', + season season[] DEFAULT '{}', hidden BOOLEAN NOT NULL, ); From 7ba006bea4971a116d737b8507a5107cb4187afa Mon Sep 17 00:00:00 2001 From: michellelin1 Date: Sun, 24 Mar 2024 14:49:10 -0700 Subject: [PATCH 5/5] edited catalog put request --- routes/catalog.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/routes/catalog.js b/routes/catalog.js index d7ef126..0c0bc94 100644 --- a/routes/catalog.js +++ b/routes/catalog.js @@ -115,12 +115,12 @@ catalogRouter.put('/:id', async (req, res) => { `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), ' : ''} + ${year ? 'year = $(year)::year[], ' : ''} ${location ? 'location = $(location), ' : ''} - ${season ? 'season = $(season), ' : ''} + ${season ? 'season = $(season)::season[], ' : ''} id = '${id}' WHERE id = '${id}' RETURNING *;`,