mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2026-01-07 05:02:06 +00:00
fix learn endpoint
This commit is contained in:
@@ -9,6 +9,8 @@ export class Card {
|
||||
shots: number
|
||||
answerImg: string
|
||||
questionImg: string
|
||||
questionVideo: string
|
||||
answerVideo: string
|
||||
rating: number
|
||||
created: Date
|
||||
updated: Date
|
||||
@@ -18,3 +20,11 @@ export class PaginatedCards {
|
||||
items: Card[]
|
||||
pagination: Pagination
|
||||
}
|
||||
|
||||
export class PaginatedCardsWithGrade {
|
||||
pagination: Pagination
|
||||
items: CardWithGrade[]
|
||||
}
|
||||
export class CardWithGrade extends Card {
|
||||
grades?: Array<{ grade: number }>
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import { createPrismaOrderBy } from '../../../infrastructure/common/helpers/get-
|
||||
import { Pagination } from '../../../infrastructure/common/pagination/pagination.service'
|
||||
import { PrismaService } from '../../../prisma.service'
|
||||
import { CreateCardDto, GetAllCardsInDeckDto, UpdateCardDto } from '../dto'
|
||||
import { PaginatedCards } from '../entities/cards.entity'
|
||||
import { PaginatedCardsWithGrade } from '../entities/cards.entity'
|
||||
|
||||
@Injectable()
|
||||
export class CardsRepository {
|
||||
@@ -53,6 +53,7 @@ export class CardsRepository {
|
||||
|
||||
async findCardsByDeckId(
|
||||
deckId: string,
|
||||
userId: string,
|
||||
{
|
||||
answer = undefined,
|
||||
question = undefined,
|
||||
@@ -60,7 +61,7 @@ export class CardsRepository {
|
||||
itemsPerPage,
|
||||
orderBy,
|
||||
}: GetAllCardsInDeckDto
|
||||
): Promise<PaginatedCards> {
|
||||
): Promise<PaginatedCardsWithGrade> {
|
||||
try {
|
||||
const where = {
|
||||
decks: {
|
||||
@@ -78,6 +79,16 @@ export class CardsRepository {
|
||||
this.prisma.card.findMany({
|
||||
orderBy: createPrismaOrderBy(orderBy) || { updated: 'desc' },
|
||||
where,
|
||||
include: {
|
||||
grades: {
|
||||
where: {
|
||||
userId,
|
||||
},
|
||||
select: {
|
||||
grade: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
skip: (currentPage - 1) * itemsPerPage,
|
||||
take: itemsPerPage,
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user