Skip to content

Commit

Permalink
completed multi-filter functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
arralia committed Mar 4, 2024
1 parent 1d90b14 commit 3f07990
Showing 1 changed file with 22 additions and 9 deletions.
31 changes: 22 additions & 9 deletions routes/catalog.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ catalogRouter.get('/', async (req, res) => {

const offset = (page - 1) * limit;

let query = ' FROM catalog WHERE 1=1';
let query = 'FROM catalog WHERE 1=1';
// removed space at beginning here

const params = [];

Expand All @@ -27,29 +28,41 @@ catalogRouter.get('/', async (req, res) => {
}

if (subject) {
query += ' AND subject = $2';
params.push(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';
params.push(array);
} else {
params.push('');
}

if (eventType) {
query += ' AND event_type = $3';
params.push(eventType);
const array = eventType.split(',');
query += ' AND event_type = ANY($3::event[])';
params.push(array);
} else {
params.push('');
}

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

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

0 comments on commit 3f07990

Please sign in to comment.