1
0
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:
Florian Bouillon 2025-05-02 00:31:04 +02:00 committed by GitHub
parent 509288ad19
commit 961c75c8a0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 113 additions and 2 deletions

View 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}}
}

View 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
}

View 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
}

View 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
}

View File

@ -247,6 +247,15 @@ server
result = Serie.findOne(lang, { name: id })?.full() result = Serie.findOne(lang, { name: id })?.full()
} }
break 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: default:
if (!endpointToField[endpoint]) { if (!endpointToField[endpoint]) {
break break

View File

@ -387,6 +387,10 @@ function filterItem(value: any, query: QueryValues<AllowedValues>): boolean {
if (typeof query === 'string' && typeof value === 'string') { if (typeof query === 'string' && typeof value === 'string') {
return query.toLowerCase() === value.toLowerCase() return query.toLowerCase() === value.toLowerCase()
} }
if (Array.isArray(value)) {
return value.includes(query)
}
return query === value return query === value
} }
@ -402,10 +406,27 @@ function filterItem(value: any, query: QueryValues<AllowedValues>): boolean {
if (typeof value === 'number' && typeof query.$inc === 'number') { if (typeof value === 'number' && typeof query.$inc === 'number') {
return value === query.$inc 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) { if ('$eq' in query) {
// handle searching using an array
if (Array.isArray(value)) {
return value.includes(query.$eq)
}
return query.$eq === value return query.$eq === value
} }

View File

@ -164,7 +164,7 @@ function parseParam(_key: string, value: string): QueryValues<unknown> {
case 'notlike': case 'notlike':
return { $not: { $inc: item } } return { $not: { $inc: item } }
case 'eq': case 'eq':
return item return { $eq: item }
case 'neq': case 'neq':
return { $not: item } return { $not: item }
case 'gte': case 'gte':
@ -179,6 +179,7 @@ function parseParam(_key: string, value: string): QueryValues<unknown> {
return null return null
case 'notnull': case 'notnull':
return { $not: null } return { $not: null }
case 'like':
default: default:
return { $inc: item } return { $inc: item }
} }