Last active
January 19, 2022 16:10
-
-
Save royib/f20dbe86cd07a81edf35fea67b281e39 to your computer and use it in GitHub Desktop.
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
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