fix schema

This commit is contained in:
2023-07-24 11:41:21 +02:00
parent 5fafb779a7
commit 86f95efe1b
3 changed files with 10 additions and 7 deletions

View File

@@ -35,7 +35,7 @@ import { Card, PaginatedCards } from '../cards/entities/cards.entity'
import { DecksService } from './decks.service'
import { UpdateDeckDto, CreateDeckDto, GetAllDecksDto } from './dto'
import { Deck, PaginatedDecks } from './entities/deck.entity'
import { Deck, DeckWithAuthor, PaginatedDecks } from './entities/deck.entity'
import {
CreateDeckCommand,
DeleteDeckByIdCommand,
@@ -77,7 +77,7 @@ export class DecksController {
cover: Express.Multer.File[]
},
@Body() createDeckDto: CreateDeckDto
): Promise<Deck> {
): Promise<DeckWithAuthor> {
const userId = req.user.id
return this.commandBus.execute(
@@ -89,7 +89,7 @@ export class DecksController {
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
@UseGuards(JwtAuthGuard)
@Get(':id')
findOne(@Param('id') id: string): Promise<Deck> {
findOne(@Param('id') id: string): Promise<DeckWithAuthor> {
return this.commandBus.execute(new GetDeckByIdCommand(id))
}
@@ -108,7 +108,7 @@ export class DecksController {
},
@Body() updateDeckDto: UpdateDeckDto,
@Req() req
): Promise<Deck> {
): Promise<DeckWithAuthor> {
return this.commandBus.execute(
new UpdateDeckCommand(id, updateDeckDto, req.user.id, files?.cover?.[0])
)

View File

@@ -11,6 +11,9 @@ export class Deck {
created: Date
updated: Date
cardsCount: number
}
export class DeckWithAuthor extends Deck {
author: DeckAuthor
}
@@ -20,7 +23,7 @@ export class DeckAuthor {
}
export class PaginatedDecks {
items: Deck[]
items: DeckWithAuthor[]
pagination: Pagination
maxCardsCount: number
}

View File

@@ -122,7 +122,7 @@ export class DecksRepository {
}
}
public async findDeckById(id: string) {
public async findDeckById(id: string): Promise<Deck> {
try {
return await this.prisma.deck.findUnique({
where: {
@@ -135,7 +135,7 @@ export class DecksRepository {
}
}
public async findDeckByCardId(cardId: string) {
public async findDeckByCardId(cardId: string): Promise<Deck> {
try {
const card = await this.prisma.card.findUnique({
where: {