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

map series to bookslist

parent 666e3ec9
Pipeline #353 passed with stage
in 1 minute and 23 seconds
...@@ -43,6 +43,9 @@ ...@@ -43,6 +43,9 @@
</router-link> </router-link>
</template> </template>
</template> </template>
<template slot="serie" slot-scope="row">
{{ row.value.name }}
</template>
</b-table> </b-table>
<TablePagination <TablePagination
:total-rows="totalRows" :total-rows="totalRows"
...@@ -85,7 +88,7 @@ export default { ...@@ -85,7 +88,7 @@ export default {
{ key: 'title', label: 'Title', sortable: true }, { key: 'title', label: 'Title', sortable: true },
{ key: 'language', label: 'Language', sortable: true }, { key: 'language', label: 'Language', sortable: true },
{ key: 'authors', label: 'Authors', sortable: true }, { key: 'authors', label: 'Authors', sortable: true },
{ key: 'serie_id', label: 'Series', sortable: true } { key: 'serie', label: 'Serie', sortable: true }
], ],
bookItems: [], bookItems: [],
totalRows: this.bookRows totalRows: this.bookRows
......
...@@ -89,7 +89,7 @@ const actions = { ...@@ -89,7 +89,7 @@ const actions = {
const newCtx = CtxTransformer.transformCtx(ctx) const newCtx = CtxTransformer.transformCtx(ctx)
const params = { const params = {
contentType: 'application/json', contentType: 'application/json',
include: 'authors', include: 'authors,serie',
...newCtx ...newCtx
} }
const response = await getBooks(params) const response = await getBooks(params)
......
...@@ -10,17 +10,26 @@ function fetchMultipleBooks (response) { ...@@ -10,17 +10,26 @@ function fetchMultipleBooks (response) {
...book.attributes ...book.attributes
} }
if (Object.hasOwnProperty.call(book, 'relationships')) { if (Object.hasOwnProperty.call(book, 'relationships')) {
if (Object.hasOwnProperty.call(book.relationships, 'authors')) { if (Object.hasOwnProperty.call(book.relationships, 'authors') && book.relationships.authors.data) {
book.relationships.authors.data.map((author) => { book.relationships.authors.data.map((author) => {
const foundAuthor = _.find(response.data.included, (included) => included.type === 'author' && included.id === author.id) const foundAuthor = _.find(response.data.included, (included) => included.type === 'author' && included.id === author.id)
const authorObj = { const authorObj = {
id: foundAuthor.id, id: foundAuthor.id,
name: foundAuthor.attributes.name ...foundAuthor.attributes
} }
authors.push(authorObj) authors.push(authorObj)
obj.authors = authors obj.authors = authors
}) })
} }
if (Object.hasOwnProperty.call(book.relationships, 'serie') && book.relationships.serie.data) {
const serieId = book.relationships.serie.data.id
const foundSerie = _.find(response.data.included, (included) => included.type === 'book_serie' && included.id === serieId)
const serieObj = {
id: foundSerie.id,
...foundSerie.attributes
}
obj.serie = serieObj
}
} }
books.push(obj) books.push(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