1
0
mirror of https://github.com/tcgdex/cards-database.git synced 2025-04-23 19:32:11 +00:00

fix: JSON endpoints not working as intended (#175)

* fix: set fetching name not stricly checking

Signed-off-by: Avior <github@avior.me>

* fix: finding card by set not testing set name

Signed-off-by: Avior <github@avior.me>
This commit is contained in:
Florian Bouillon 2021-11-18 11:52:10 +01:00 committed by GitHub
parent 7f83a6f8eb
commit b55cab7c6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 2 deletions

View File

@ -82,7 +82,10 @@ export default class Card implements LocalCard {
const res = (require(`../../../generated/${lang}/cards.json`) as Array<SDKCard>).find((c) => { const res = (require(`../../../generated/${lang}/cards.json`) as Array<SDKCard>).find((c) => {
return objectLoop(params, (it, key) => { return objectLoop(params, (it, key) => {
if (key === 'set' && typeof it === 'string') { if (key === 'set' && typeof it === 'string') {
return c['set'].id.toLowerCase().includes(it.toLowerCase()) || c['set'].name.toLowerCase().includes(it.toLowerCase()) return (
c['set'].id.toLowerCase().includes(it.toLowerCase()) ||
c['set'].name?.toLowerCase()?.includes(it.toLowerCase())
)
} }
if (typeof it === "string") { if (typeof it === "string") {
return c[key as 'localId'].toLowerCase().includes(it.toLowerCase()) return c[key as 'localId'].toLowerCase().includes(it.toLowerCase())

View File

@ -60,7 +60,9 @@ export default class Set implements LocalSet {
public static findOne(lang: SupportedLanguages, params: Partial<Record<keyof Set, any>> = {}) { public static findOne(lang: SupportedLanguages, params: Partial<Record<keyof Set, any>> = {}) {
const res = (require(`../../../generated/${lang}/sets.json`) as Array<SDKSet>).find((c) => { const res = (require(`../../../generated/${lang}/sets.json`) as Array<SDKSet>).find((c) => {
return objectLoop(params, (it, key) => { return objectLoop(params, (it, key) => {
if (typeof it === 'string') { if (key === 'id' || key === 'name') {
return c[key as 'id'].toLowerCase() === it.toLowerCase()
} else if (typeof it === 'string') {
return c[key as 'id'].toLowerCase().includes(it.toLowerCase()) return c[key as 'id'].toLowerCase().includes(it.toLowerCase())
} }
return c[key as 'id'].includes(it) return c[key as 'id'].includes(it)