1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-06-28 23:09:18 +00:00

fix: Invalid card when searching using the set and localid (#472)

This commit is contained in:
2024-01-08 00:40:31 +01:00
committed by GitHub
parent 8684fb14e4
commit 33007d83bc
7 changed files with 53 additions and 17 deletions

View File

@ -69,7 +69,7 @@ export default class Card implements LocalCard {
}
public static findOne(lang: SupportedLanguages, query: Query<SDKCard>) {
const res = handleValidation(this.getAll(lang), query)
const res = handleSort(handleValidation(this.getAll(lang), query), query)
if (res.length === 0) {
return undefined
}

View File

@ -30,8 +30,8 @@ const endpointToField: Record<string, keyof SDKCard> = {
}
server
// Midleware that handle caching
.use(apicache.middleware('1 day', (req: Request) => req.method === 'GET', {}))
// Midleware that handle caching only in production and on GET requests
.use(apicache.middleware('1 day', (req: Request) => process.env.NODE_ENV === 'production' && req.method === 'GET', {}))
// .get('/cache/performance', (req, res) => {
// res.json(apicache.getPerformance())
@ -186,23 +186,23 @@ server
let result: any | undefined
switch (endpoint) {
case 'cards':
result = Card.findOne(lang, { filters: { id }})?.full()
result = Card.findOne(lang, { filters: { id }, strict: true })?.full()
if (!result) {
result = Card.findOne(lang, { filters: { name: id }})?.full()
result = Card.findOne(lang, { filters: { name: id }, strict: true })?.full()
}
break
case 'sets':
result = Set.findOne(lang, { filters: { id }})?.full()
result = Set.findOne(lang, { filters: { id }, strict: true })?.full()
if (!result) {
result = Set.findOne(lang, {filters: { name: id }})?.full()
result = Set.findOne(lang, {filters: { name: id }, strict: true })?.full()
}
break
case 'series':
result = Serie.findOne(lang, { filters: { id }})?.full()
result = Serie.findOne(lang, { filters: { id }, strict: true })?.full()
if (!result) {
result = Serie.findOne(lang, { filters: { name: id }})?.full()
result = Serie.findOne(lang, { filters: { name: id }, strict: true })?.full()
}
break
default:
@ -242,7 +242,7 @@ server
switch (endpoint) {
case 'sets':
result = Card
.findOne(lang, { filters: { localId: subid, set: id }})?.full()
.findOne(lang, { filters: { localId: subid, set: id }, strict: true})?.full()
break
}
if (!result) {