Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
0x43
eBookHub-frontend
Commits
3869e722
Commit
3869e722
authored
Apr 12, 2019
by
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
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/store/modules/book.js
View file @
3869e722
...
...
@@ -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
})
...
...
src/transformers/BookTransformer.js
View file @
3869e722
...
...
@@ -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
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment