refactor a bit

This commit is contained in:
2023-06-18 14:52:37 +02:00
parent ca976cfe5d
commit 892cee4a7b
6 changed files with 11 additions and 19 deletions

View File

@@ -9,10 +9,10 @@ import {
GetAllDecksHandler,
UpdateDeckHandler,
GetAllCardsInDeckHandler,
CreateCardHandler,
} from './use-cases'
import { DecksRepository } from './infrastructure/decks.repository'
import { CardsRepository } from '../cards/infrastructure/cards.repository'
import { CreateCardHandler } from './use-cases/create-card-use-case'
const commandHandlers = [
CreateDeckHandler,

View File

@@ -4,3 +4,4 @@ export * from './get-deck-by-id-use-case'
export * from './delete-deck-by-id-use-case'
export * from './update-deck-use-case'
export * from './get-all-cards-in-deck-use-case'
export * from './create-card-use-case'

View File

@@ -17,9 +17,12 @@ export class UpdateDeckHandler implements ICommandHandler<UpdateDeckCommand> {
async execute(command: UpdateDeckCommand) {
const deck = await this.deckRepository.findDeckById(command.deckId)
if (!deck) throw new NotFoundException(`Deck with id ${command.deckId} not found`)
if (!deck) {
throw new NotFoundException(`Deck with id ${command.deckId} not found`)
}
if (deck.userId !== command.userId) {
throw new BadRequestException(`You can't change a deck that you don't own`)
throw new BadRequestException(`You can't modify a deck that you don't own`)
}
return await this.deckRepository.updateDeckById(command.deckId, command.deck)