1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-06-12 15:59:18 +00:00

fix: dex-id url not returning valid cards & filtering not working using dexId (#722)

This commit is contained in:
2025-05-02 00:31:04 +02:00
committed by GitHub
parent 509288ad19
commit 961c75c8a0
7 changed files with 113 additions and 2 deletions

View File

@ -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

View File

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

View File

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