Commit 7e4fc42d authored by Mycha de Vrees's avatar Mycha de Vrees
Browse files

fixes for book fetching

parent d36b4eb9
Pipeline #347 failed with stage
in 1 minute and 21 seconds
......@@ -40,7 +40,7 @@
<template slot="authors" slot-scope="row">
<template v-for="(value, index) in row.value" >
<router-link :to="{ name: 'Author view', params: { id: value.id }}" :key="index">
{{ value.name }}{{ index-1 === row.value.length ? '' : ',' }}
{{ value.name }}{{ index + 1 === row.value.length ? '' : ',' }}
</router-link>
</template>
</template>
......
......@@ -36,8 +36,8 @@
* @vue-data {Boolean} isBusy - determine isBusy state for table
*/
// import { TablePagination } from '@/components'
import { mapActions } from 'vuex'
// import _ from 'lodash'
import { mapActions, mapGetters } from 'vuex'
import _ from 'lodash'
export default {
props: ['id'],
......@@ -46,20 +46,18 @@ export default {
book: {}
}
},
computed: {
...mapGetters(['getCurrentBook'])
},
methods: {
...mapActions(['fetchBook']),
async fillBook () {
async _fetchBook () {
await this.fetchBook({id: this.id, vm: this})
this.book = this.$store.state.book.current
this.book = _.cloneDeep(this.getCurrentBook)
}
},
created () {
this.fillBook()
this._fetchBook()
}
// watch: {
// author () {
// this.author = this.$store.state.author.current
// }
// }
}
</script>
......@@ -25,6 +25,9 @@ const getters = {
*/
getAllBooks (state) {
return state.all
},
getCurrentBook (state) {
return state.current
}
}
......
......@@ -24,7 +24,6 @@ function fetchMultipleBooks (response) {
}
function fetchSingleBook (response) {
console.log(response)
const authors = []
const obj = {
id: response.data.data.id,
......@@ -32,7 +31,11 @@ function fetchSingleBook (response) {
}
response.data.data.relationships.authors.data.map((author) => {
const foundAuthor = _.find(response.data.included, (included) => included.type === 'author' && included.id === author.id)
authors.push(foundAuthor.attributes.name)
const authorObj = {
id: foundAuthor.id,
name: foundAuthor.attributes.name
}
authors.push(authorObj)
obj.authors = authors
})
return obj
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment