traxxx/assets/js/actors/actions.js

92 lines
2.3 KiB
JavaScript
Raw Normal View History

2019-12-15 22:01:48 +00:00
import { graphql, get } from '../api';
function curateActor(actor) {
const curatedActor = {
...actor,
avatar: actor.avatar[0],
origin: {
country: actor.originCountry,
},
};
return curatedActor;
}
function initActorActions(store, _router) {
2019-12-15 22:01:48 +00:00
async function fetchActorBySlug(actorSlug) {
const { actor } = await graphql(`
query Actor($actorSlug:String!) {
actor: actorBySlug(slug:$actorSlug) {
id
name
slug
avatar: actorsMediasByTargetId(condition: { role:"avatar" }) {
thumbnail
}
originCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
aliases: actorsByAliasFor {
id
name
slug
}
}
}
`, {
actorSlug,
});
return curateActor(actor);
}
async function fetchActors({ _commit }, { actorSlug, limit = 100 }) {
if (actorSlug) {
return fetchActorBySlug(actorSlug);
}
2019-12-15 22:01:48 +00:00
const { actors } = await graphql(`
query Actors($limit:Int) {
actors(first:$limit) {
id
name
slug
avatar: actorsMediasByTargetId(condition: { role:"avatar" }) {
thumbnail
}
originCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
}
}
`, {
limit,
});
console.log(actors);
return actors.map(actor => curateActor(actor));
}
async function fetchActorReleases({ _commit }, actorId) {
const releases = await get(`/actors/${actorId}/releases`, {
filter: store.state.ui.filter,
after: store.getters.after,
before: store.getters.before,
});
return releases;
}
return {
fetchActors,
fetchActorReleases,
};
}
export default initActorActions;