fix infinite loop

This commit is contained in:
2023-08-07 14:34:12 +02:00
parent fff0288659
commit 39010b73d6
2 changed files with 16 additions and 8 deletions

View File

@@ -193,13 +193,20 @@ export class DecksController {
description: 'Save the grade of a card',
summary: 'Save the grade of a card',
})
async saveGrade(@Param('id') id: string, @Req() req, @Body() body: SaveGradeDto) {
const saved = await this.commandBus.execute(
new SaveGradeCommand(req.user.id, { cardId: body.cardId, grade: body.grade })
)
async saveGrade(@Param('id') deckId: string, @Req() req, @Body() body: SaveGradeDto) {
const promises = [
this.commandBus.execute(new GetRandomCardInDeckCommand(req.user.id, deckId, body.cardId)),
this.commandBus.execute(
new SaveGradeCommand(req.user.id, { cardId: body.cardId, grade: body.grade })
),
]
return await this.commandBus.execute(
new GetRandomCardInDeckCommand(req.user.id, saved.deckId, saved.id)
)
try {
const [card] = await Promise.all(promises)
return card
} catch (error) {
throw error
}
}
}