mirror of
https://github.com/tcgdex/cards-database.git
synced 2025-04-22 10:52:10 +00:00
fix: dec IDs not working
Signed-off-by: Avior <git@avior.me>
This commit is contained in:
parent
0616b98038
commit
0486f277b4
@ -5,7 +5,7 @@ meta {
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/en/cards?name=eq:Pikachu|Pichu&hp=lt:70&localId=not:tg&id=neq:cel25-5
|
||||
url: {{BASE_URL}}/v2/en/cards?name=eq:Pikachu|Pichu&hp=lt:70&localId=not:tg&id=neq:cel25-5&sort:field=updated
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
@ -15,9 +15,10 @@ params:query {
|
||||
hp: lt:70
|
||||
localId: not:tg
|
||||
id: neq:cel25-5
|
||||
sort:field: updated
|
||||
}
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
res.body: length 85
|
||||
res.body.length: gte 85
|
||||
}
|
||||
|
19
.bruno/dex-ids/Get dex ID 2.bru
Normal file
19
.bruno/dex-ids/Get dex ID 2.bru
Normal file
@ -0,0 +1,19 @@
|
||||
meta {
|
||||
name: Get dex ID 2
|
||||
type: http
|
||||
seq: 3
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/en/cards?dexId=eq:2
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
params:query {
|
||||
dexId: eq:2
|
||||
}
|
||||
|
||||
assert {
|
||||
res.body.length: gte 18
|
||||
}
|
16
.bruno/dex-ids/Get dex ID.bru
Normal file
16
.bruno/dex-ids/Get dex ID.bru
Normal file
@ -0,0 +1,16 @@
|
||||
meta {
|
||||
name: Get dex ID
|
||||
type: http
|
||||
seq: 2
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/en/dex-ids/1
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
assert {
|
||||
res.body.cards.length: gte 18
|
||||
res.body.name: eq '1'
|
||||
}
|
15
.bruno/dex-ids/List dex IDS.bru
Normal file
15
.bruno/dex-ids/List dex IDS.bru
Normal file
@ -0,0 +1,15 @@
|
||||
meta {
|
||||
name: List dex IDS
|
||||
type: http
|
||||
seq: 1
|
||||
}
|
||||
|
||||
get {
|
||||
url: {{BASE_URL}}/v2/en/dex-ids
|
||||
body: none
|
||||
auth: none
|
||||
}
|
||||
|
||||
assert {
|
||||
res.body.length: gte 800
|
||||
}
|
@ -17,5 +17,5 @@ params:query {
|
||||
|
||||
assert {
|
||||
res.status: eq 200
|
||||
res.body.length: lt 0
|
||||
res.body.length: gt 0
|
||||
}
|
||||
|
@ -4,7 +4,7 @@
|
||||
"main": "dist/index.js",
|
||||
"scripts": {
|
||||
"compile": "bun compiler/index.ts",
|
||||
"dev": "bun --watch src/index.ts",
|
||||
"dev": "MAX_WORKERS=1 bun --watch src/index.ts",
|
||||
"validate": "tsc --noEmit --project ./tsconfig.json",
|
||||
"start": "bun src/index.ts"
|
||||
},
|
||||
|
@ -41,7 +41,7 @@ const cards = {
|
||||
'zh-cn': zhcn,
|
||||
} as const
|
||||
|
||||
type LocalCard = Omit<SDKCard, 'set'> & {set: () => TCGSet}
|
||||
type LocalCard = Omit<SDKCard, 'set'> & { set: () => TCGSet }
|
||||
|
||||
interface variants {
|
||||
normal?: boolean;
|
||||
@ -101,7 +101,10 @@ export default class Card implements LocalCard {
|
||||
}
|
||||
|
||||
public static find(lang: SupportedLanguages, query: Query<SDKCard>) {
|
||||
return executeQuery(Card.getAll(lang), query).data.map((it) => new Card(lang, it))
|
||||
if (query.dexId) {
|
||||
query.dexId = { $in: query.dexId }
|
||||
}
|
||||
return executeQuery(Card.getAll(lang), query, { debug: true }).data.map((it) => new Card(lang, it))
|
||||
}
|
||||
|
||||
public static findOne(lang: SupportedLanguages, query: Query<SDKCard>) {
|
||||
|
@ -253,7 +253,7 @@ server
|
||||
}
|
||||
result = {
|
||||
name: id,
|
||||
cards: Card.find(lang, { [endpointToField[endpoint]]: id })
|
||||
cards: Card.find(lang, { [endpointToField[endpoint]]: { $eq: id } })
|
||||
.map((c) => c.resume())
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import type RFC7807 from './RFCs/RFC7807'
|
||||
export enum Errors {
|
||||
LANGUAGE_INVALID = 'language-invalid',
|
||||
NOT_FOUND = 'not-found',
|
||||
INVALID_KEY = 'invalid-key',
|
||||
|
||||
GENERAL = 'general'
|
||||
}
|
||||
@ -12,6 +13,7 @@ export enum Errors {
|
||||
const titles: Record<Errors, string> = {
|
||||
[Errors.LANGUAGE_INVALID]: 'The chosen language is not available in the database',
|
||||
[Errors.NOT_FOUND]: 'The resource you are trying to reach does not exists',
|
||||
[Errors.INVALID_KEY]: 'The key you used is not a valid format',
|
||||
|
||||
[Errors.GENERAL]: 'An unknown error occured, please contact a developper with this message'
|
||||
}
|
||||
@ -19,6 +21,7 @@ const titles: Record<Errors, string> = {
|
||||
const status: Record<Errors, number> = {
|
||||
[Errors.LANGUAGE_INVALID]: 404,
|
||||
[Errors.NOT_FOUND]: 404,
|
||||
[Errors.INVALID_KEY]: 400,
|
||||
|
||||
[Errors.GENERAL]: 500
|
||||
}
|
||||
|
@ -118,7 +118,7 @@ export type QueryComparisonOperator<Value> = {
|
||||
/**
|
||||
* the remote source value must be one of the proposed values
|
||||
*/
|
||||
$in: Array<Value>
|
||||
$in: Array<Value> | Value
|
||||
} | {
|
||||
/**
|
||||
* laxist validation of the remote value
|
||||
@ -350,7 +350,7 @@ function filterValue<T extends AllowedValues>(value: unknown, query: QueryValues
|
||||
// loop through each keys of the query
|
||||
// eslint-disable-next-line arrow-body-style
|
||||
return objectLoop(query as any, (querySubValue: unknown, queryKey: string) => {
|
||||
return filterItem(value, {[queryKey]: querySubValue } as QueryValues<T>)
|
||||
return filterItem(value, { [queryKey]: querySubValue } as QueryValues<T>)
|
||||
})
|
||||
}
|
||||
|
||||
@ -390,6 +390,10 @@ function filterItem(value: any, query: QueryValues<AllowedValues>): boolean {
|
||||
return query === value
|
||||
}
|
||||
|
||||
if (Array.isArray(value) && '$in' in query && !Array.isArray(query.$in)) {
|
||||
return value.includes(query.$in)
|
||||
}
|
||||
|
||||
/**
|
||||
* Array checking and $in
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user