Skip to content

Instantly share code, notes, and snippets.

@saeedhajinasiri
Created April 15, 2021 18:46
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 saeedhajinasiri/faab9efbd7495627e34d94333a127660 to your computer and use it in GitHub Desktop.
Save saeedhajinasiri/faab9efbd7495627e34d94333a127660 to your computer and use it in GitHub Desktop.
import { Injectable, HttpException } from '@nestjs/common';
import { BOOKS } from '../mocks/books.mock';
@Injectable()
export class BooksService {
books = BOOKS;
getBooks(): Promise {
return new Promise(resolve => {
resolve(this.books);
});
}
getBook(bookID): Promise {
let id = Number(bookID);
return new Promise(resolve => {
const book = this.books.find(book => book.id === id);
if (!book) {
throw new HttpException('Book does not exist!', 404);
}
resolve(book);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment