mirror of
https://github.com/ershisan99/flashcards-api.git
synced 2025-12-17 12:33:22 +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 { DecksService } from './decks.service'
|
||||||
import { UpdateDeckDto, CreateDeckDto, GetAllDecksDto } from './dto'
|
import { UpdateDeckDto, CreateDeckDto, GetAllDecksDto } from './dto'
|
||||||
import { Deck, PaginatedDecks } from './entities/deck.entity'
|
import { Deck, DeckWithAuthor, PaginatedDecks } from './entities/deck.entity'
|
||||||
import {
|
import {
|
||||||
CreateDeckCommand,
|
CreateDeckCommand,
|
||||||
DeleteDeckByIdCommand,
|
DeleteDeckByIdCommand,
|
||||||
@@ -77,7 +77,7 @@ export class DecksController {
|
|||||||
cover: Express.Multer.File[]
|
cover: Express.Multer.File[]
|
||||||
},
|
},
|
||||||
@Body() createDeckDto: CreateDeckDto
|
@Body() createDeckDto: CreateDeckDto
|
||||||
): Promise<Deck> {
|
): Promise<DeckWithAuthor> {
|
||||||
const userId = req.user.id
|
const userId = req.user.id
|
||||||
|
|
||||||
return this.commandBus.execute(
|
return this.commandBus.execute(
|
||||||
@@ -89,7 +89,7 @@ export class DecksController {
|
|||||||
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
|
@ApiUnauthorizedResponse({ description: 'Unauthorized' })
|
||||||
@UseGuards(JwtAuthGuard)
|
@UseGuards(JwtAuthGuard)
|
||||||
@Get(':id')
|
@Get(':id')
|
||||||
findOne(@Param('id') id: string): Promise<Deck> {
|
findOne(@Param('id') id: string): Promise<DeckWithAuthor> {
|
||||||
return this.commandBus.execute(new GetDeckByIdCommand(id))
|
return this.commandBus.execute(new GetDeckByIdCommand(id))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ export class DecksController {
|
|||||||
},
|
},
|
||||||
@Body() updateDeckDto: UpdateDeckDto,
|
@Body() updateDeckDto: UpdateDeckDto,
|
||||||
@Req() req
|
@Req() req
|
||||||
): Promise<Deck> {
|
): Promise<DeckWithAuthor> {
|
||||||
return this.commandBus.execute(
|
return this.commandBus.execute(
|
||||||
new UpdateDeckCommand(id, updateDeckDto, req.user.id, files?.cover?.[0])
|
new UpdateDeckCommand(id, updateDeckDto, req.user.id, files?.cover?.[0])
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -11,6 +11,9 @@ export class Deck {
|
|||||||
created: Date
|
created: Date
|
||||||
updated: Date
|
updated: Date
|
||||||
cardsCount: number
|
cardsCount: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export class DeckWithAuthor extends Deck {
|
||||||
author: DeckAuthor
|
author: DeckAuthor
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,7 +23,7 @@ export class DeckAuthor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class PaginatedDecks {
|
export class PaginatedDecks {
|
||||||
items: Deck[]
|
items: DeckWithAuthor[]
|
||||||
pagination: Pagination
|
pagination: Pagination
|
||||||
maxCardsCount: number
|
maxCardsCount: number
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ export class DecksRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findDeckById(id: string) {
|
public async findDeckById(id: string): Promise<Deck> {
|
||||||
try {
|
try {
|
||||||
return await this.prisma.deck.findUnique({
|
return await this.prisma.deck.findUnique({
|
||||||
where: {
|
where: {
|
||||||
@@ -135,7 +135,7 @@ export class DecksRepository {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async findDeckByCardId(cardId: string) {
|
public async findDeckByCardId(cardId: string): Promise<Deck> {
|
||||||
try {
|
try {
|
||||||
const card = await this.prisma.card.findUnique({
|
const card = await this.prisma.card.findUnique({
|
||||||
where: {
|
where: {
|
||||||
|
|||||||
Reference in New Issue
Block a user