Skip to content

Commit d1c30cd

Browse files
committed
handle array filters
1 parent cabf65c commit d1c30cd

File tree

1 file changed

+21
-11
lines changed

1 file changed

+21
-11
lines changed

src/utils/searchHelper.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,33 @@ export function newSearch(filters, productData) {
3838
filter: {}
3939
}
4040

41-
console.log(filters)
4241
if (Object.keys(filters).length > 0) {
4342
query.filter.op = 'and'
4443
query.filter.args = []
4544

4645
for (const key in filters) {
4746
console.log(key, filters[key])
48-
const operator = key === 'sensors' ? 'in' : '='
49-
query.filter.args.push({
50-
op: operator,
51-
args: [
52-
{
53-
property: key
54-
},
55-
filters[key]
56-
]
57-
})
47+
if (productData.constraints.properties[key].type === 'array') {
48+
query.filter.args.push({
49+
op: 'in',
50+
args: [
51+
{
52+
property: key
53+
},
54+
[filters[key]]
55+
]
56+
})
57+
} else {
58+
query.filter.args.push({
59+
op: '=',
60+
args: [
61+
{
62+
property: key
63+
},
64+
filters[key]
65+
]
66+
})
67+
}
5868
}
5969
}
6070
console.log(query)

0 commit comments

Comments
 (0)