traxxx/assets/js/actors/actions.js

141 lines
4.1 KiB
JavaScript

import { graphql, get } from '../api';
function curateActor(actor) {
const curatedActor = {
...actor,
avatar: actor.avatar[0],
height: actor.heightMetric && {
metric: actor.heightMetric,
imperial: actor.heightImperial,
},
weight: actor.weightMetric && {
metric: actor.weightMetric,
imperial: actor.weightImperial,
},
origin: actor.birthCountry && {
city: actor.birthCity,
state: actor.birthState,
country: actor.birthCountry,
},
residence: actor.residenceCountry && {
city: actor.residenceCity,
state: actor.residenceState,
country: actor.residenceCountry,
},
};
return curatedActor;
}
function initActorActions(store, _router) {
async function fetchActorBySlug(actorSlug) {
const { actor } = await graphql(`
query Actor($actorSlug:String!) {
actor: actorBySlug(slug:$actorSlug) {
id
name
slug
gender
birthdate
age
ethnicity
bust
waist
hip
heightMetric: height(units:METRIC)
heightImperial: height(units:IMPERIAL)
weightMetric: weight(units:METRIC)
weightImperial: weight(units:IMPERIAL)
hasTattoos
hasPiercings
tattoos
piercings
avatar: actorsMediasByTargetId(condition: { role:"avatar" }) {
thumbnail
path
}
photos: actorsMediasByTargetId(condition: { role:"photo" }) {
id
thumbnail
path
index
}
birthCity
birthState
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
residenceCity
residenceState
residenceCountry: countryByResidenceCountryAlpha2 {
alpha2
name
alias
}
social: actorsSocialsByTargetId {
id
url
platform
}
aliases: actorsByAliasFor {
id
name
slug
}
}
}
`, {
actorSlug,
});
return curateActor(actor);
}
async function fetchActors({ _commit }, { actorSlug, limit = 100 }) {
if (actorSlug) {
return fetchActorBySlug(actorSlug);
}
const { actors } = await graphql(`
query Actors($limit:Int) {
actors(first:$limit) {
id
name
slug
avatar: actorsMediasByTargetId(condition: { role:"avatar" }) {
thumbnail
}
birthCountry: countryByBirthCountryAlpha2 {
alpha2
name
alias
}
}
}
`, {
limit,
});
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;