|
|
|
@ -28,6 +28,16 @@ export default new Vuex.Store({
|
|
|
|
|
throw "No book was found by that id"
|
|
|
|
|
|
|
|
|
|
},
|
|
|
|
|
REMOVE_BOOK: (state, book) => {
|
|
|
|
|
for (let item of state.books) {
|
|
|
|
|
if (item.id == book.id) {
|
|
|
|
|
let index = state.books.indexOf(item)
|
|
|
|
|
state.books.splice(index, 1)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
throw "No book was found by that id"
|
|
|
|
|
},
|
|
|
|
|
}, //mutations
|
|
|
|
|
actions: {
|
|
|
|
|
LOAD_BOOKS_LIST({commit}) {
|
|
|
|
@ -51,8 +61,8 @@ export default new Vuex.Store({
|
|
|
|
|
context.commit('ADD_BOOK', book)
|
|
|
|
|
resolve()
|
|
|
|
|
})
|
|
|
|
|
.catch((data) => {
|
|
|
|
|
console.log(data)
|
|
|
|
|
.catch((error) => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
reject()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
@ -64,11 +74,24 @@ export default new Vuex.Store({
|
|
|
|
|
context.commit('UPDATE_BOOK', book)
|
|
|
|
|
resolve()
|
|
|
|
|
})
|
|
|
|
|
.catch(data => {
|
|
|
|
|
console.log(data)
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
reject()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
DELETE_BOOK(context, book){
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
appService.deleteBook(book)
|
|
|
|
|
.then(data => {
|
|
|
|
|
context.commit('REMOVE_BOOK', book)
|
|
|
|
|
resolve()
|
|
|
|
|
})
|
|
|
|
|
.catch(error => {
|
|
|
|
|
console.log(error)
|
|
|
|
|
reject()
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
},//actions
|
|
|
|
|
})
|
|
|
|
|