Implementing the createBookCollection method

The following is the code for the next method:

createBookCollection(): void {
const newBookCollectionName: string =
this._view.getNewBookCollectionName();

console.log("Creating a new book collection: ",
newBookCollectionName);

const newBookCollection: MediaCollection<Book> = new
MediaCollection<Book>(Book, newBookCollectionName);
this._bookCollections.set(newBookCollection.identifier,
newBookCollection);

this._bookService.saveMediaCollection(newBookCollection).then(()
=> {
console.log(`New book collection called
"
${newBookCollection.name}"
saved successfully. Identifier: `
,
newBookCollection.identifier);
this._view.clearNewBookCollectionForm();
this._view.renderBookCollection(newBookCollection);
}).catch(_ => {
this._view.displayErrorMessage(`Failed to save the new book
collection called
${newBookCollectionName}`);
});
}

Here, we get the information we need out of the view. We adapt our map by associating the collection identifier with the newly created media collection. Finally, we use the service to persist in our collection.