Commit 3869e722 authored by Mycha de Vrees's avatar Mycha de Vrees
Browse files

fetch authors for single book as well

parent dc89d0f2
Pipeline #345 failed with stage
in 1 minute and 22 seconds
......@@ -63,7 +63,11 @@ const actions = {
try {
commit(BOOKS_FETCHING, true, null)
const newCtx = CtxTransformer.transformCtx(ctx)
const params = { contentType: 'application/json', include: 'authors', ...newCtx }
const params = {
contentType: 'application/json',
include: 'authors',
...newCtx
}
const response = await getBooks(params)
const books = BookTransformer.fetch(response)
const { count } = response.data.meta
......@@ -82,7 +86,11 @@ const actions = {
async fetchBook ({commit}, {id, vm}) {
try {
commit(BOOKS_FETCHING, true, null)
const params = { contentType: 'application/json', bookId: id }
const params = {
contentType: 'application/json',
include: 'authors',
bookId: id
}
const response = await getBook(params)
const book = BookTransformer.fetch(response)
commit(BOOK_FETCH_SUCCESS, {current: book})
......
......@@ -20,11 +20,17 @@ function fetchMultipleBooks (response) {
}
function fetchSingleBook (response) {
console.log(response)
const authors = []
const obj = {
id: response.data.data.id,
...response.data.data.attributes
}
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)
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