Skip to content

Commit 44a6e1e

Browse files
committed
fix: category filter parsing using JSON in jobs APIs
1 parent 5fb918a commit 44a6e1e

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

src/controllers/jobsController.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,19 @@ const paginationForJobs = async (req, res) => {
3636
/* ----------------------------
3737
MULTI-CATEGORY FILTER (only if non-empty)
3838
---------------------------- */
39-
if (category && category.trim() !== '') {
40-
const categoryList = category.split(',').map((c) => c.trim());
41-
conditions.push({ category: { $in: categoryList } });
39+
40+
if (category) {
41+
let categoryList = [];
42+
43+
try {
44+
categoryList = JSON.parse(category);
45+
} catch (e) {
46+
console.error('Invalid category format:', category);
47+
}
48+
49+
if (Array.isArray(categoryList) && categoryList.length > 0) {
50+
conditions.push({ category: { $in: categoryList } });
51+
}
4252
}
4353

4454
const query = conditions.length ? { $and: conditions } : {};
@@ -99,9 +109,18 @@ const getJobSummaries = async (req, res) => {
99109
conditions.push({ title: { $in: [position.trim()] } });
100110
}
101111

102-
if (category && category.trim() !== '') {
103-
const categoryList = category.split(',').map((c) => c.trim());
104-
conditions.push({ category: { $in: categoryList } });
112+
if (category) {
113+
let categoryList = [];
114+
115+
try {
116+
categoryList = JSON.parse(category);
117+
} catch (e) {
118+
console.error('Invalid category format:', category);
119+
}
120+
121+
if (Array.isArray(categoryList) && categoryList.length > 0) {
122+
conditions.push({ category: { $in: categoryList } });
123+
}
105124
}
106125

107126
const query = conditions.length ? { $and: conditions } : {};

0 commit comments

Comments
 (0)