mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-17 05:09:26 +00:00
fix: cardsCount
This commit is contained in:
@@ -108,8 +108,6 @@ model deck {
|
|||||||
name String
|
name String
|
||||||
isPrivate Boolean @default(false)
|
isPrivate Boolean @default(false)
|
||||||
cover String? @db.VarChar(500)
|
cover String? @db.VarChar(500)
|
||||||
isDeleted Boolean?
|
|
||||||
isBlocked Boolean?
|
|
||||||
created DateTime @default(now())
|
created DateTime @default(now())
|
||||||
updated DateTime @updatedAt
|
updated DateTime @updatedAt
|
||||||
author user @relation(fields: [userId], references: [id], onDelete: Cascade)
|
author user @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common'
|
import { Injectable, InternalServerErrorException, Logger } from '@nestjs/common'
|
||||||
|
import { omit } from 'remeda'
|
||||||
|
|
||||||
import { PrismaService } from '../../../prisma.service'
|
import { PrismaService } from '../../../prisma.service'
|
||||||
import { GetAllDecksDto } from '../dto'
|
import { GetAllDecksDto } from '../dto'
|
||||||
@@ -172,14 +173,18 @@ export class DecksRepository {
|
|||||||
const modifiedDecks = decks.map(deck => {
|
const modifiedDecks = decks.map(deck => {
|
||||||
const cardsCount = deck.cardsCount
|
const cardsCount = deck.cardsCount
|
||||||
|
|
||||||
return {
|
return omit(
|
||||||
...deck,
|
{
|
||||||
cardsCount: typeof cardsCount === 'bigint' ? Number(cardsCount) : cardsCount,
|
...deck,
|
||||||
author: {
|
cardsCount: typeof cardsCount === 'bigint' ? Number(cardsCount) : cardsCount,
|
||||||
id: deck.authorId,
|
isPrivate: !!deck.isPrivate,
|
||||||
name: deck.authorName,
|
author: {
|
||||||
|
id: deck.authorId,
|
||||||
|
name: deck.authorName,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
}
|
['authorId', 'authorName']
|
||||||
|
)
|
||||||
})
|
})
|
||||||
const max = await this.prisma
|
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;`
|
.$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