mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-17 05:09:26 +00:00
fix schema
This commit is contained in:
@@ -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])
|
||||
)
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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: {
|
||||
|
||||
Reference in New Issue
Block a user