diff --git a/routes/catalog.js b/routes/catalog.js index 8802a68..4a97d75 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 a2a19be..31b97a4 100644 --- a/server/schema/catalog.sql +++ b/server/schema/catalog.sql @@ -6,12 +6,12 @@ CREATE TYPE season AS ENUM ('spring', 'summer', 'fall'); 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, );