Skip to content

Commit

Permalink
updated get request filters
Browse files Browse the repository at this point in the history
  • Loading branch information
michellelin1 committed Mar 21, 2024
1 parent e0784e9 commit f9f1c91
Showing 1 changed file with 4 additions and 12 deletions.
16 changes: 4 additions & 12 deletions routes/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,39 +29,31 @@ 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('');
}

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('');
}

if (season) {
const array = season.split(',');
query += ' AND season = ANY($4::season[])';
query += ' AND season && $4::season[]';
params.push(array);
} else {
params.push('');
}

if (year) {
const array = year.split(',');
query += ' AND year = ANY($5::year[])';
query += ' AND year && $5::year[]';
params.push(array);
} else {
params.push('');
Expand Down

0 comments on commit f9f1c91

Please sign in to comment.