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 @@
</router-link>
</template>
</template>
<template slot="serie" slot-scope="row">
{{ row.value.name }}
</template>
</b-table>
<TablePagination
:total-rows="totalRows"
......@@ -85,7 +88,7 @@ export default {
{ key: 'title', label: 'Title', sortable: true },
{ key: 'language', label: 'Language', sortable: true },
{ key: 'authors', label: 'Authors', sortable: true },
{ key: 'serie_id', label: 'Series', sortable: true }
{ key: 'serie', label: 'Serie', sortable: true }
],
bookItems: [],
totalRows: this.bookRows
......
......@@ -89,7 +89,7 @@ const actions = {
const newCtx = CtxTransformer.transformCtx(ctx)
const params = {
contentType: 'application/json',
include: 'authors',
include: 'authors,serie',
...newCtx
}
const response = await getBooks(params)
......
......@@ -10,17 +10,26 @@ function fetchMultipleBooks (response) {
...book.attributes
}
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) => {
const foundAuthor = _.find(response.data.included, (included) => included.type === 'author' && included.id === author.id)
const authorObj = {
id: foundAuthor.id,
name: foundAuthor.attributes.name
...foundAuthor.attributes
}
authors.push(authorObj)
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)
})
......
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