From 67254b5555264d020e089165fbc3500fc60d5189 Mon Sep 17 00:00:00 2001 From: andres Date: Sat, 20 Jan 2024 16:29:05 +0100 Subject: [PATCH] fix: cardsCount --- prisma/schema.prisma | 2 -- .../decks/infrastructure/decks.repository.ts | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 326eb44..3871388 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -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) diff --git a/src/modules/decks/infrastructure/decks.repository.ts b/src/modules/decks/infrastructure/decks.repository.ts index 6396d07..ccf4d07 100644 --- a/src/modules/decks/infrastructure/decks.repository.ts +++ b/src/modules/decks/infrastructure/decks.repository.ts @@ -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;`