import { graphql, get } from '../api'; import { releasePosterFragment, releaseActorsFragment, releaseTagsFragment, } from '../fragments'; import { curateActor, curateRelease } from '../curate'; import getDateRange from '../get-date-range'; function initActorActions(store, _router) { async function fetchActorById({ _commit }, { actorId, limit = 100, range = 'latest' }) { const { before, after, orderBy } = getDateRange(range); const { actor } = await graphql(` query Actor( $actorId: Int! $limit:Int = 1000, $after:Date = "1900-01-01", $before:Date = "2100-01-01", $orderBy:[ReleasesActorsOrderBy!] $exclude: [String!] ) { actor(id: $actorId) { id name slug realName gender dateOfBirth dateOfDeath age ageAtDeath ethnicity cup bust waist hip naturalBoobs heightMetric: height(units:METRIC) heightImperial: height(units:IMPERIAL) weightMetric: weight(units:METRIC) weightImperial: weight(units:IMPERIAL) hairColor hairLength eyes hasTattoos hasPiercings tattoos piercings description createdAt updatedAt network { id name slug } avatar: avatarMedia { id path thumbnail lazy hash comment copyright sfw: sfwMedia { id thumbnail path comment } } profiles: actorsProfiles { description descriptionHash network { id slug name } site { id slug name } avatar: avatarMedia { id path thumbnail lazy hash comment copyright sfw: sfwMedia { id thumbnail path comment } } } birthCity birthState birthCountry: countryByBirthCountryAlpha2 { alpha2 name alias } residenceCity residenceState residenceCountry: countryByResidenceCountryAlpha2 { alpha2 name alias } social: actorsSocials { id url platform } aliases: actorsByAliasFor { id name slug } releases: releasesActors( filter: { release: { date: { lessThan: $before, greaterThan: $after, }, releasesTagsConnection: { none: { tag: { slug: { in: $exclude } } } } } }, first: $limit, orderBy: $orderBy ) { release { id url title date slug ${releaseActorsFragment} ${releaseTagsFragment} ${releasePosterFragment} site { id name slug url network { id name slug url } } } } } } `, { actorId, limit, after, before, orderBy: orderBy === 'DATE_DESC' ? 'RELEASE_BY_RELEASE_ID__DATE_DESC' : 'RELEASE_BY_RELEASE_ID__DATE_ASC', exclude: store.state.ui.filter, }); return curateActor(actor, null, curateRelease); } async function fetchActors({ _commit }, { limit = 10, pageNumber = 1, letter, gender, }) { const genderFilter = gender === null ? 'isNull: true' : `equalTo: "${gender}"`; const { connection: { actors, totalCount } } = await graphql(` query Actors( $limit: Int, $offset: Int = 0, $letter: String! = "", ) { connection: actorsConnection( first: $limit, offset: $offset orderBy: NAME_ASC filter: { aliasFor: { isNull: true } name: { startsWith: $letter } gender: { ${genderFilter} } } ) { totalCount actors: nodes { id name slug age ageAtDeath dateOfBirth dateOfDeath gender network { id name slug } avatar: avatarMedia { id path thumbnail lazy comment copyright sfw: sfwMedia { id thumbnail path comment } } birthCountry: countryByBirthCountryAlpha2 { alpha2 name alias } } } } `, { offset: Math.max(0, (pageNumber - 1)) * limit, limit, letter, }); return { actors: actors.map(actor => curateActor(actor)), totalCount, }; } 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 { fetchActorById, fetchActors, fetchActorReleases, }; } export default initActorActions;