mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-26 20:59:28 +00:00
fix: update docs
This commit is contained in:
@@ -26,7 +26,7 @@ import {
|
||||
import { JwtAuthGuard } from '../auth/guards'
|
||||
|
||||
import { UpdateCardDto } from './dto'
|
||||
import { Card } from './entities/cards.entity'
|
||||
import { Card, CardWithGrade } from './entities/cards.entity'
|
||||
import { DeleteCardByIdCommand, GetDeckByIdCommand, UpdateCardCommand } from './use-cases'
|
||||
|
||||
@ApiTags('Cards')
|
||||
@@ -39,7 +39,7 @@ export class CardsController {
|
||||
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
|
||||
@ApiNotFoundResponse({ description: 'Card not found' })
|
||||
@Get(':id')
|
||||
findOne(@Param('id') id: string): Promise<Card> {
|
||||
findOne(@Param('id') id: string): Promise<CardWithGrade> {
|
||||
return this.commandBus.execute(new GetDeckByIdCommand(id))
|
||||
}
|
||||
|
||||
|
||||
@@ -20,11 +20,20 @@ export class PaginatedCards {
|
||||
pagination: Pagination
|
||||
}
|
||||
|
||||
export class PaginatedCardsWithGrades {
|
||||
pagination: Pagination
|
||||
items: CardWithGrades[]
|
||||
}
|
||||
|
||||
export class CardWithGrades extends Card {
|
||||
grades?: Array<{ grade: number }>
|
||||
}
|
||||
|
||||
export class PaginatedCardsWithGrade {
|
||||
pagination: Pagination
|
||||
items: CardWithGrade[]
|
||||
}
|
||||
|
||||
export class CardWithGrade extends Card {
|
||||
grades?: Array<{ grade: number }>
|
||||
grade: number
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import {
|
||||
import { Pagination } from '../../../infrastructure/common/pagination/pagination.service'
|
||||
import { PrismaService } from '../../../prisma.service'
|
||||
import { CreateCardDto, GetAllCardsInDeckDto, UpdateCardDto } from '../dto'
|
||||
import { CardWithGrade, PaginatedCardsWithGrade } from '../entities/cards.entity'
|
||||
import { CardWithGrades, PaginatedCardsWithGrades } from '../entities/cards.entity'
|
||||
|
||||
@Injectable()
|
||||
export class CardsRepository {
|
||||
@@ -50,7 +50,7 @@ export class CardsRepository {
|
||||
itemsPerPage,
|
||||
orderBy,
|
||||
}: GetAllCardsInDeckDto
|
||||
): Promise<PaginatedCardsWithGrade> {
|
||||
): Promise<PaginatedCardsWithGrades> {
|
||||
if (!orderBy || orderBy === 'null') {
|
||||
orderBy = 'updated-desc'
|
||||
}
|
||||
@@ -92,7 +92,7 @@ export class CardsRepository {
|
||||
itemsPerPage
|
||||
)) satisfies Array<any>
|
||||
|
||||
const cards: CardWithGrade[] = cardsRaw.map(({ userGrade, ...card }) => ({
|
||||
const cards: CardWithGrades[] = cardsRaw.map(({ userGrade, ...card }) => ({
|
||||
...card,
|
||||
grades: [
|
||||
{
|
||||
@@ -196,8 +196,8 @@ export class CardsRepository {
|
||||
}
|
||||
}
|
||||
|
||||
private async getSmartRandomCard(cards: Array<CardWithGrade>): Promise<CardWithGrade> {
|
||||
const selectionPool: Array<CardWithGrade> = []
|
||||
private async getSmartRandomCard(cards: Array<CardWithGrades>): Promise<CardWithGrades> {
|
||||
const selectionPool: Array<CardWithGrades> = []
|
||||
|
||||
cards.forEach(card => {
|
||||
// Calculate the average grade for the card
|
||||
@@ -218,9 +218,9 @@ export class CardsRepository {
|
||||
}
|
||||
|
||||
private async getNotDuplicateRandomCard(
|
||||
cards: Array<CardWithGrade>,
|
||||
cards: Array<CardWithGrades>,
|
||||
previousCardId: string
|
||||
): Promise<CardWithGrade> {
|
||||
): Promise<CardWithGrades> {
|
||||
const randomCard = await this.getSmartRandomCard(cards)
|
||||
|
||||
if (!randomCard) {
|
||||
|
||||
Reference in New Issue
Block a user