From fc9ecfafed011c8ed041015da4657a01f7832018 Mon Sep 17 00:00:00 2001 From: ctc-devops <90984711+ctc-devops@users.noreply.github.com> Date: Sun, 24 Mar 2024 14:57:34 -0700 Subject: [PATCH] Catalog Create Event Form Backend Updates (#60) * Create a pull trequest for branch 57-catalog-create-event-form-backend * accommodating for the multi select fields in the catalog form * updated get request filters * update catalog scheme + removed location from post req * edited catalog put request --------- Co-authored-by: Lana Ramadan Co-authored-by: michellelin1 --- routes/catalog.js | 16 ++++------------ server/schema/catalog.sql | 14 +++++++------- 2 files changed, 11 insertions(+), 19 deletions(-) diff --git a/routes/catalog.js b/routes/catalog.js index e286012..1b53de5 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(''); diff --git a/server/schema/catalog.sql b/server/schema/catalog.sql index e32df3e..10a0185 100644 --- a/server/schema/catalog.sql +++ b/server/schema/catalog.sql @@ -6,12 +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, - hidden boolean NOT NULL + event_type event[] NOT NULL DEFAULT '{}', + subject subject[] NOT NULL DEFAULT '{}', + description VARCHAR(256), + year year[] NOT NULL DEFAULT '{}', + season season[] NOT NULL DEFAULT '{}', + hidden BOOLEAN NOT NULL, );