Created
July 17, 2024 08:22
-
-
Save PCreations/d37d8789a5ca0673e4361fa98ba00e02 to your computer and use it in GitHub Desktop.
3374f79ea11b.diff
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-1,11 +1,15 @@ | |
import { Injectable } from '@nestjs/common'; | |
import { BookRepository } from './book-repository.port'; | |
+import { BookAlreadyExistsError } from './book-already-exists.error'; | |
@Injectable() | |
export class AddBookUseCase { | |
constructor(private readonly bookRepository: BookRepository) {} | |
- execute(book: { title: string }) { | |
+ async execute(book: { title: string }) { | |
+ if (await this.bookRepository.doesBookExist(book.title)) { | |
+ throw new BookAlreadyExistsError(book.title); | |
+ } | |
return this.bookRepository.save(book); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment