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:
parent
4c96331b93
commit
07a8ad0b8e
23
.bruno/cards/multiple.bru
Normal file
23
.bruno/cards/multiple.bru
Normal 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
|
||||
}
|
@ -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)) }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user