1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-04-22 10:52:10 +00:00

fix: Add missing multi value filtering (#564)

This commit is contained in:
Florian Bouillon 2024-10-29 14:52:11 +01:00 committed by GitHub
parent 4c96331b93
commit 07a8ad0b8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 59 additions and 24 deletions

23
.bruno/cards/multiple.bru Normal file
View File

@ -0,0 +1,23 @@
meta {
name: Multiple values
type: http
seq: 1
}
get {
url: {{BASE_URL}}/v2/en/cards?name=eq:Pikachu|Pichu&hp=lt:70&localId=not:tg&id=neq:cel25-5
body: none
auth: none
}
params:query {
name: eq:Pikachu|Pichu
hp: lt:70
localId: not:tg
id: neq:cel25-5
}
assert {
res.status: eq 200
res.body: length 85
}

View File

@ -163,31 +163,43 @@ function parseParam(_key: string, value: string): QueryValues<unknown> {
}
}
if (/^\d+\.?\d*$/g.test(compared)) {
compared = Number.parseFloat(compared)
}
function process(item: string | number) {
switch (filter) {
case 'not':
case 'notlike':
return { $not: { $inc: compared }}
return { $not: { $inc: item } }
case 'eq':
return compared
return item
case 'neq':
return { $not: compared }
return { $not: item }
case 'gte':
return { $gte: compared }
return { $gte: item }
case 'gt':
return { $gt: compared }
return { $gt: item }
case 'lt':
return { $lt: compared }
return { $lt: item }
case 'lte':
return { $lte: compared }
return { $lte: item }
case 'null':
return null
case 'notnull':
return { $not: null }
default:
return { $inc: compared }
return { $inc: item }
}
}
if (/^\d+\.?\d*$/g.test(compared)) {
return process(Number.parseFloat(compared))
}
// @deprecated the `,` separator
// TODO: only use the `|` separator
const items = compared.split(compared.includes('|') ? '|' : ',')
if (items.length === 1) {
return process(items[0])
}
return { $or: items.map((it) => process(it)) }
}