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)) {
|
function process(item: string | number) {
|
||||||
compared = Number.parseFloat(compared)
|
switch (filter) {
|
||||||
|
case 'not':
|
||||||
|
case 'notlike':
|
||||||
|
return { $not: { $inc: item } }
|
||||||
|
case 'eq':
|
||||||
|
return item
|
||||||
|
case 'neq':
|
||||||
|
return { $not: item }
|
||||||
|
case 'gte':
|
||||||
|
return { $gte: item }
|
||||||
|
case 'gt':
|
||||||
|
return { $gt: item }
|
||||||
|
case 'lt':
|
||||||
|
return { $lt: item }
|
||||||
|
case 'lte':
|
||||||
|
return { $lte: item }
|
||||||
|
case 'null':
|
||||||
|
return null
|
||||||
|
case 'notnull':
|
||||||
|
return { $not: null }
|
||||||
|
default:
|
||||||
|
return { $inc: item }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (filter) {
|
if (/^\d+\.?\d*$/g.test(compared)) {
|
||||||
case 'not':
|
return process(Number.parseFloat(compared))
|
||||||
case 'notlike':
|
|
||||||
return { $not: { $inc: compared }}
|
|
||||||
case 'eq':
|
|
||||||
return compared
|
|
||||||
case 'neq':
|
|
||||||
return { $not: compared }
|
|
||||||
case 'gte':
|
|
||||||
return { $gte: compared }
|
|
||||||
case 'gt':
|
|
||||||
return { $gt: compared }
|
|
||||||
case 'lt':
|
|
||||||
return { $lt: compared }
|
|
||||||
case 'lte':
|
|
||||||
return { $lte: compared }
|
|
||||||
case 'null':
|
|
||||||
return null
|
|
||||||
case 'notnull':
|
|
||||||
return { $not: null }
|
|
||||||
default:
|
|
||||||
return { $inc: 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