mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-16 20:59:26 +00:00
fix: cardsCount
This commit is contained in:
@@ -108,8 +108,6 @@ model deck {
|
||||
name String
|
||||
isPrivate Boolean @default(false)
|
||||
cover String? @db.VarChar(500)
|
||||
isDeleted Boolean?
|
||||
isBlocked Boolean?
|
||||
created DateTime @default(now())
|
||||
updated DateTime @updatedAt
|
||||
author user @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common'
|
||||
import { omit } from 'remeda'
|
||||
|
||||
import { PrismaService } from '../../../prisma.service'
|
||||
import { GetAllDecksDto } from '../dto'
|
||||
@@ -172,14 +173,18 @@ export class DecksRepository {
|
||||
const modifiedDecks = decks.map(deck => {
|
||||
const cardsCount = deck.cardsCount
|
||||
|
||||
return {
|
||||
...deck,
|
||||
cardsCount: typeof cardsCount === 'bigint' ? Number(cardsCount) : cardsCount,
|
||||
author: {
|
||||
id: deck.authorId,
|
||||
name: deck.authorName,
|
||||
return omit(
|
||||
{
|
||||
...deck,
|
||||
cardsCount: typeof cardsCount === 'bigint' ? Number(cardsCount) : cardsCount,
|
||||
isPrivate: !!deck.isPrivate,
|
||||
author: {
|
||||
id: deck.authorId,
|
||||
name: deck.authorName,
|
||||
},
|
||||
},
|
||||
}
|
||||
['authorId', 'authorName']
|
||||
)
|
||||
})
|
||||
const max = await this.prisma
|
||||
.$queryRaw`SELECT MAX(card_count) as maxCardsCount FROM (SELECT COUNT(*) as card_count FROM card GROUP BY deckId) AS card_counts;`
|
||||
|
||||
Reference in New Issue
Block a user