Created
April 15, 2021 18:47
-
-
Save saeedhajinasiri/72ab1ced9cdac8174b6af4cd61e81e8d 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, HttpException } from '@nestjs/common'; | |
import { BOOKS } from '../mocks/books.mock'; | |
@Injectable() | |
export class BooksService { | |
books = BOOKS; | |
... | |
deleteBook(bookID): Promise { | |
let id = Number(bookID); | |
return new Promise(resolve => { | |
let index = this.books.findIndex(book => book.id === id); | |
if (index === -1) { | |
throw new HttpException('Book does not exist!', 404); | |
} | |
this.books.splice(1, index); | |
resolve(this.books); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment