Skip to content

Commit

Permalink
fix: no data was returned when filtering with set (#568)
Browse files Browse the repository at this point in the history
  • Loading branch information
Aviortheking authored Nov 5, 2024
1 parent 07a8ad0 commit 64bcd05
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
meta {
name: 567 - invalid data returned when filtering using set
type: http
seq: 9
}

get {
url: {{BASE_URL}}/v2/en/cards?name=umbreon&set=evolving skies
body: none
auth: none
}

params:query {
name: umbreon
set: evolving skies
}

assert {
res.status: eq 200
res.body.length: lt 0
}
34 changes: 27 additions & 7 deletions server/src/V2/endpoints/jsonEndpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,17 +128,37 @@ server
let result: unknown

switch (endpoint) {
case 'cards':
case 'cards': {
if ('set' in query) {
const tmp = query.set
delete query.set
query.$or = [{
'set.id': tmp
}, {
'set.name': tmp
}]
}
result = Card
.find(lang, query)
.map((c) => c.resume())
break

case 'sets':
}

case 'sets': {
if ('serie' in query) {
const tmp = query.serie
delete query.serie
query.$or = [{
'serie.id': tmp
}, {
'serie.name': tmp
}]
}
result = TCGSet
.find(lang, query)
.map((c) => c.resume())
break
}
case 'series':
result = Serie
.find(lang, query)
Expand Down Expand Up @@ -233,8 +253,8 @@ server
}
result = {
name: id,
cards: Card.find(lang, {[endpointToField[endpoint]]: id})
.map((c) => c.resume())
cards: Card.find(lang, { [endpointToField[endpoint]]: id })
.map((c) => c.resume())
}
}
if (!result) {
Expand Down Expand Up @@ -269,8 +289,8 @@ server
case 'sets':
// allow the dev to use a non prefixed value like `10` instead of `010` for newer sets
result = Card
// @ts-expect-error normal behavior until the filtering is more fiable
.findOne(lang, { localId: { $or: [subid.padStart(3, '0'), subid]}, $or: [{ 'set.id': id }, { 'set.name': id }] })?.full()
// @ts-expect-error normal behavior until the filtering is more fiable
.findOne(lang, { localId: { $or: [subid.padStart(3, '0'), subid] }, $or: [{ 'set.id': id }, { 'set.name': id }] })?.full()
break
}
if (!result) {
Expand Down

0 comments on commit 64bcd05

Please sign in to comment.