fix: update docs

This commit is contained in:
2024-01-20 19:28:22 +01:00
parent 28b5066894
commit 289512bc48
6 changed files with 46 additions and 30 deletions

View File

@@ -31,7 +31,7 @@ import { Pagination } from '../../infrastructure/common/pagination/pagination.se
import { SaveGradeDto } from '../auth/dto'
import { JwtAuthGuard } from '../auth/guards'
import { CreateCardDto, GetAllCardsInDeckDto } from '../cards/dto'
import { Card, PaginatedCards } from '../cards/entities/cards.entity'
import { Card, CardWithGrade, PaginatedCardsWithGrade } from '../cards/entities/cards.entity'
import { CreateDeckDto, GetAllDecksDto, UpdateDeckDto } from './dto'
import { GetRandomCardDto } from './dto/get-random-card.dto'
@@ -134,7 +134,7 @@ export class DecksController {
@Param('id') id: string,
@Req() req,
@Query() query: GetAllCardsInDeckDto
): Promise<PaginatedCards> {
): Promise<PaginatedCardsWithGrade> {
const finalQuery = Pagination.getPaginationData(query)
return this.commandBus.execute(new GetAllCardsInDeckCommand(req.user.id, id, finalQuery))
@@ -176,7 +176,7 @@ export class DecksController {
@Param('id') id: string,
@Req() req,
@Query() query: GetRandomCardDto
): Promise<Card> {
): Promise<CardWithGrade> {
return this.commandBus.execute(
new GetRandomCardInDeckCommand(req.user.id, id, query.previousCardId)
)
@@ -189,14 +189,14 @@ export class DecksController {
@ApiNoContentResponse({ description: 'Grade saved' })
@ApiOkResponse({
description: 'A new random card in the deck. Will never return the same card that was sent',
type: Card,
type: CardWithGrade,
})
@Post(':id/learn')
@ApiOperation({
description: 'Save the grade of a card',
summary: 'Save the grade of a card',
})
async saveGrade(@Req() req, @Body() body: SaveGradeDto) {
async saveGrade(@Req() req, @Body() body: SaveGradeDto): Promise<CardWithGrade> {
return await this.commandBus.execute(
new SaveGradeCommand(req.user.id, { cardId: body.cardId, grade: body.grade })
)

View File

@@ -12,11 +12,11 @@ export enum DecksOrderBy {
'name-asc' = 'name-asc',
'author.name-asc' = 'author.name-asc',
'created-asc' = 'created-asc',
'cardsCount-decs' = 'cardsCount-decs',
'updated-decs' = 'updated-decs',
'name-decs' = 'name-decs',
'author.name-decs' = 'author.name-decs',
'created-decs' = 'created-decs',
'cardsCount-desc' = 'cardsCount-desc',
'updated-desc' = 'updated-desc',
'name-desc' = 'name-desc',
'author.name-desc' = 'author.name-desc',
'created-desc' = 'created-desc',
}
export class GetAllDecksDto extends PaginationDto {
@@ -50,7 +50,9 @@ export class GetAllDecksDto extends PaginationDto {
@IsOrderBy()
@ApiProperty({
enum: DecksOrderBy,
required: false,
})
@IsEnum(DecksOrderBy)
@IsOptional()
@IsEnum(DecksOrderBy, {})
orderBy?: DecksOrderBy
}

View File

@@ -3,7 +3,11 @@ import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'
import { pick } from 'remeda'
import { GetAllCardsInDeckDto } from '../../cards/dto'
import { PaginatedCards, PaginatedCardsWithGrade } from '../../cards/entities/cards.entity'
import {
PaginatedCards,
PaginatedCardsWithGrade,
PaginatedCardsWithGrades,
} from '../../cards/entities/cards.entity'
import { CardsRepository } from '../../cards/infrastructure/cards.repository'
import { DecksRepository } from '../infrastructure/decks.repository'
@@ -21,7 +25,8 @@ export class GetAllCardsInDeckHandler implements ICommandHandler<GetAllCardsInDe
private readonly cardsRepository: CardsRepository,
private readonly decksRepository: DecksRepository
) {}
private transformGrade(cards: PaginatedCardsWithGrade): PaginatedCards {
private transformGrade(cards: PaginatedCardsWithGrades): PaginatedCardsWithGrade {
return {
...cards,
items: cards.items.map(card =>
@@ -31,18 +36,18 @@ export class GetAllCardsInDeckHandler implements ICommandHandler<GetAllCardsInDe
grade: card.grades[0]?.grade || 0,
},
[
'id',
'question',
'answer',
'deckId',
'questionImg',
'answerImg',
'questionVideo',
'answerVideo',
'created',
'updated',
'shots',
'deckId',
'grade',
'id',
'question',
'questionImg',
'questionVideo',
'shots',
'updated',
'userId',
]
)