Skip to content

Instantly share code, notes, and snippets.

@PCreations
Created July 17, 2024 08:22
Show Gist options
  • Save PCreations/d37d8789a5ca0673e4361fa98ba00e02 to your computer and use it in GitHub Desktop.
Save PCreations/d37d8789a5ca0673e4361fa98ba00e02 to your computer and use it in GitHub Desktop.
3374f79ea11b.diff
-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