Skip to content

Instantly share code, notes, and snippets.

@royib
Last active January 19, 2022 16:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save royib/f20dbe86cd07a81edf35fea67b281e39 to your computer and use it in GitHub Desktop.
Save royib/f20dbe86cd07a81edf35fea67b281e39 to your computer and use it in GitHub Desktop.
import { Injectable } from '@nestjs/common';
import { Book } from '../../../core/entities';
import { IDataServices, ICrmServices } from '../../../core/abstracts';
@Injectable()
export class BookServices {
constructor(
private dataServices: IDataServices,
private crmServices: ICrmServices,
) {}
getAllBooks(): Promise<Book[]> {
return this.dataServices.books.getAll();
}
getBookById(id: any): Promise<Book> {
return this.dataServices.books.get(id);
}
async createBook(book: Book): Promise<Book> {
try {
// call to our dependencies
const createdBook = await this.dataServices.books.create(book);
await this.crmServices.bookAdded(createdBook);
return createdBook;
} catch (error) {
throw error;
}
}
updateBook(bookId: string, book: Book): Promise<Book> {
return this.dataServices.books.update(bookId, book);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment