fix grade orderby

This commit is contained in:
2023-08-07 16:40:21 +02:00
parent dab78cd2a1
commit 2b7b967382
5 changed files with 95 additions and 38 deletions

View File

@@ -194,19 +194,12 @@ export class DecksController {
summary: 'Save the grade of a card',
})
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 })
),
]
const saved = await this.commandBus.execute(
new SaveGradeCommand(req.user.id, { cardId: body.cardId, grade: body.grade })
)
try {
const [card] = await Promise.all(promises)
return card
} catch (error) {
throw error
}
return await this.commandBus.execute(
new GetRandomCardInDeckCommand(req.user.id, saved.deckId, saved.id)
)
}
}