November 2019
Beginner
804 pages
20h 1m
English
Next, let's copy and adapt the createBook method.
For this one, we need to add a book: Book parameter. That way, users of the service will be able to pass in the book to add to the collection.
Here is the new code for this method:
createBook(collectionIdentifier: string, book: Book): void {
if (!collectionIdentifier) {
throw new Error('The collection identifier is required to create a new book!');
}
if (!this._bookCollections.has(collectionIdentifier) || !this._bookCollections.get(collectionIdentifier)) {
console.error('Tried to add a book to an unknown collection. Identifier: ', collectionIdentifier);
this.displayErrorMessage('Failed to create the new book!');
return;
}
const existingCollection = this._bookCollections.get(collectionIdentifier); ...Read now
Unlock full access