mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-05-04 16:42:10 +00:00
fix: dex-id url not returning valid cards & filtering not working using dexId
(#722)
This commit is contained in:
parent
509288ad19
commit
961c75c8a0
21
.bruno/dex-ids/get-by-dex-id.bru
Normal file
21
.bruno/dex-ids/get-by-dex-id.bru
Normal file
@ -0,0 +1,21 @@
|
||||
meta {
|
||||
name: Get by Dex ID
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/en/dex-ids/{{ID}}
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
vars:pre-request {
|
||||
ID: 162
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
res.body.cards.length: gte 8
|
||||
res.body.name: eq {{ID}}
|
||||
}
|
20
.bruno/filtering/end-star-pattern.bru
Normal file
20
.bruno/filtering/end-star-pattern.bru
Normal file
@ -0,0 +1,20 @@
|
||||
meta {
|
||||
name: End Star Pattern
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/en/cards?name=*chu
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:query {
|
||||
name: *chu
|
||||
}
|
||||
|
||||
assert {
|
||||
res.body.length: gt 3
|
||||
res.body[1].name: neq Pikachu on the Ball
|
||||
}
|
19
.bruno/filtering/searching-using-the-dex-id.bru
Normal file
19
.bruno/filtering/searching-using-the-dex-id.bru
Normal file
@ -0,0 +1,19 @@
|
||||
meta {
|
||||
name: dexId Search
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/ja/cards?dexId=eq:357
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:query {
|
||||
dexId: eq:357
|
||||
}
|
||||
|
||||
assert {
|
||||
res.body.length: eq 3
|
||||
}
|
20
.bruno/filtering/start-star-pattern.bru
Normal file
20
.bruno/filtering/start-star-pattern.bru
Normal file
@ -0,0 +1,20 @@
|
||||
meta {
|
||||
name: Start star Pattern
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/en/cards?name=fu*
|
||||
body: none
|
||||
auth: inherit
|
||||
}
|
||||
|
||||
params:query {
|
||||
name: fu*
|
||||
}
|
||||
|
||||
assert {
|
||||
res.body.length: gt 3
|
||||
res.body[1].name: neq Stufful
|
||||
}
|
@ -247,6 +247,15 @@ server
|
||||
result = Serie.findOne(lang, { name: id })?.full()
|
||||
}
|
||||
break
|
||||
case 'dex-ids': {
|
||||
result = {
|
||||
name: parseInt(id, 10),
|
||||
// @ts-expect-error current behavior is normal
|
||||
cards: Card.find(lang, { dexId: { $eq: parseInt(id, 10) }})
|
||||
.map((c) => c.resume())
|
||||
}
|
||||
break
|
||||
}
|
||||
default:
|
||||
if (!endpointToField[endpoint]) {
|
||||
break
|
||||
|
@ -387,6 +387,10 @@ function filterItem(value: any, query: QueryValues<AllowedValues>): boolean {
|
||||
if (typeof query === 'string' && typeof value === 'string') {
|
||||
return query.toLowerCase() === value.toLowerCase()
|
||||
}
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
return value.includes(query)
|
||||
}
|
||||
return query === value
|
||||
}
|
||||
|
||||
@ -402,10 +406,27 @@ function filterItem(value: any, query: QueryValues<AllowedValues>): boolean {
|
||||
if (typeof value === 'number' && typeof query.$inc === 'number') {
|
||||
return value === query.$inc
|
||||
}
|
||||
return (value.toString() as string).toLowerCase().includes(query.$inc!.toString()!.toLowerCase())
|
||||
|
||||
const valueTmp = value.toString().toLowerCase()
|
||||
const comp = query.$inc!.toString().toLowerCase()
|
||||
const ignoreStars = comp.startsWith('*') && comp.endsWith('*')
|
||||
|
||||
if (!ignoreStars && comp.startsWith('*')) {
|
||||
return valueTmp.endsWith(comp.slice(1))
|
||||
} else if (!ignoreStars && comp.endsWith('*')) {
|
||||
return valueTmp.startsWith(comp.slice(0, -1))
|
||||
} else if (ignoreStars) {
|
||||
return valueTmp.includes(comp.slice(1, -1))
|
||||
}
|
||||
return valueTmp.includes(comp)
|
||||
}
|
||||
|
||||
if ('$eq' in query) {
|
||||
// handle searching using an array
|
||||
if (Array.isArray(value)) {
|
||||
return value.includes(query.$eq)
|
||||
}
|
||||
|
||||
return query.$eq === value
|
||||
}
|
||||
|
||||
|
@ -164,7 +164,7 @@ function parseParam(_key: string, value: string): QueryValues<unknown> {
|
||||
case 'notlike':
|
||||
return { $not: { $inc: item } }
|
||||
case 'eq':
|
||||
return item
|
||||
return { $eq: item }
|
||||
case 'neq':
|
||||
return { $not: item }
|
||||
case 'gte':
|
||||
@ -179,6 +179,7 @@ function parseParam(_key: string, value: string): QueryValues<unknown> {
|
||||
return null
|
||||
case 'notnull':
|
||||
return { $not: null }
|
||||
case 'like':
|
||||
default:
|
||||
return { $inc: item }
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user