forked from DebaucheryLibrarian/traxxx
175 lines
4.7 KiB
JavaScript
175 lines
4.7 KiB
JavaScript
import { graphql } from '../api';
|
|
|
|
function curateRelease(release) {
|
|
const curatedRelease = {
|
|
...release,
|
|
actors: release.actors.map(({ actor }) => ({
|
|
...actor,
|
|
avatar: actor.avatar[0],
|
|
origin: {
|
|
country: actor.originCountry,
|
|
},
|
|
})),
|
|
poster: release.poster[0],
|
|
network: release.site.network,
|
|
tags: release.tags.map(({ tag }) => tag),
|
|
};
|
|
|
|
if (release.trailer) [curatedRelease.trailer] = release.trailer;
|
|
|
|
return curatedRelease;
|
|
}
|
|
|
|
function initReleasesActions(_store, _router) {
|
|
async function fetchReleases({ _commit }, { limit = 100 }) {
|
|
/*
|
|
const releases = await get('/releases', {
|
|
filter: store.state.ui.filter,
|
|
after: store.getters.after,
|
|
before: store.getters.before,
|
|
});
|
|
*/
|
|
|
|
const { releases } = await graphql(`
|
|
query Releases($limit:Int) {
|
|
releases(first:$limit, orderBy: DATE_DESC) {
|
|
id
|
|
title
|
|
description
|
|
date
|
|
duration
|
|
createdAt
|
|
shootId
|
|
url
|
|
actors: actorsAssociateds {
|
|
actor {
|
|
id
|
|
name
|
|
slug
|
|
birthdate
|
|
originCountry: countryByBirthCountryAlpha2 {
|
|
alpha2
|
|
name
|
|
alias
|
|
}
|
|
avatar: actorsMediasByTargetId(condition: { role: "avatar" }) {
|
|
thumbnail
|
|
}
|
|
}
|
|
}
|
|
poster: releasesMediasByTargetId(condition: { role: "poster" }) {
|
|
index
|
|
path
|
|
thumbnail
|
|
}
|
|
tags: releasesTagsByTargetId {
|
|
tag {
|
|
name
|
|
priority
|
|
slug
|
|
id
|
|
}
|
|
}
|
|
site {
|
|
id
|
|
name
|
|
slug
|
|
url
|
|
network {
|
|
id
|
|
name
|
|
slug
|
|
url
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`, {
|
|
limit,
|
|
});
|
|
|
|
return releases.map(release => curateRelease(release));
|
|
}
|
|
|
|
async function fetchReleaseById({ _commit }, releaseId) {
|
|
// const release = await get(`/releases/${releaseId}`);
|
|
|
|
const { release } = await graphql(`
|
|
query Release($releaseId:Int!) {
|
|
release(id: $releaseId) {
|
|
id
|
|
title
|
|
description
|
|
date
|
|
duration
|
|
createdAt
|
|
shootId
|
|
url
|
|
actors: actorsAssociateds {
|
|
actor {
|
|
id
|
|
name
|
|
slug
|
|
birthdate
|
|
originCountry: countryByBirthCountryAlpha2 {
|
|
alpha2
|
|
name
|
|
alias
|
|
}
|
|
avatar: actorsMediasByTargetId(condition: { role: "avatar" }) {
|
|
thumbnail
|
|
}
|
|
}
|
|
}
|
|
poster: releasesMediasByTargetId(condition: { role: "poster" }) {
|
|
index
|
|
path
|
|
thumbnail
|
|
}
|
|
photos: releasesMediasByTargetId(condition: { role: "photo" }) {
|
|
index
|
|
path
|
|
thumbnail
|
|
}
|
|
trailer: releasesMediasByTargetId(condition: { role: "trailer" }) {
|
|
index
|
|
path
|
|
thumbnail
|
|
}
|
|
tags: releasesTagsByTargetId {
|
|
tag {
|
|
name
|
|
priority
|
|
slug
|
|
id
|
|
}
|
|
}
|
|
site {
|
|
id
|
|
name
|
|
slug
|
|
url
|
|
network {
|
|
id
|
|
name
|
|
slug
|
|
url
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`, {
|
|
releaseId: Number(releaseId),
|
|
});
|
|
|
|
return curateRelease(release);
|
|
}
|
|
|
|
return {
|
|
fetchReleases,
|
|
fetchReleaseById,
|
|
};
|
|
}
|
|
|
|
export default initReleasesActions;
|