mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-17 05:09:26 +00:00
fix 500 error
This commit is contained in:
@@ -52,12 +52,12 @@ export class GetRandomCardInDeckHandler implements ICommandHandler<GetRandomCard
|
|||||||
const randomCard = await this.getSmartRandomCard(cards)
|
const randomCard = await this.getSmartRandomCard(cards)
|
||||||
|
|
||||||
if (!randomCard) {
|
if (!randomCard) {
|
||||||
this.logger.error(`No cards found in deck with id ${randomCard.deckId}`, {
|
this.logger.error(`No cards found in deck}`, {
|
||||||
previousCardId,
|
previousCardId,
|
||||||
randomCard,
|
randomCard,
|
||||||
cards,
|
cards,
|
||||||
})
|
})
|
||||||
throw new NotFoundException(`No cards found in deck with id ${randomCard.deckId}`)
|
throw new NotFoundException(`No cards found in deck`)
|
||||||
}
|
}
|
||||||
if (randomCard.id === previousCardId && cards.length !== 1) {
|
if (randomCard.id === previousCardId && cards.length !== 1) {
|
||||||
return this.getNotDuplicateRandomCard(cards, previousCardId)
|
return this.getNotDuplicateRandomCard(cards, previousCardId)
|
||||||
@@ -78,6 +78,11 @@ export class GetRandomCardInDeckHandler implements ICommandHandler<GetRandomCard
|
|||||||
command.userId,
|
command.userId,
|
||||||
command.deckId
|
command.deckId
|
||||||
)
|
)
|
||||||
|
|
||||||
|
if (!cards.length) {
|
||||||
|
throw new NotFoundException(`No cards found in deck with id ${command.deckId}`)
|
||||||
|
}
|
||||||
|
|
||||||
const smartRandomCard = await this.getNotDuplicateRandomCard(cards, command.previousCardId)
|
const smartRandomCard = await this.getNotDuplicateRandomCard(cards, command.previousCardId)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user