import config from 'config'; import { graphql, get } from '../api'; import { releaseFields, 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 = 10, pageNumber = 1, range = 'latest', }) { const { before, after, orderBy } = getDateRange(range); const includeTags = router.currentRoute.query.tags ? router.currentRoute.query.tags.split(',') : []; const { actor, connection: { releases, totalCount } } = await graphql(` query Actor( $actorId: Int! $limit:Int = 10, $offset:Int = 0, $after:Date = "1900-01-01", $before:Date = "2100-01-01", $orderBy:[ReleasesActorsOrderBy!] $selectableTags: [String], $excludeTags: [String!] ${includeTags.length > 0 ? '$includeTags: [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 entity { id name slug type parent { id name slug type } } avatar: avatarMedia { id path thumbnail lazy hash comment copyright sfw: sfwMedia { id thumbnail path comment } } profiles: actorsProfiles(orderBy: PRIORITY_DESC) { description descriptionHash entity { id name slug type independent parent { id name slug type } } 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 } tags(selectableTags: $selectableTags) { id name slug priority } releasesConnection: releasesActorsConnection( filter: { release: { date: { lessThan: $before, greaterThan: $after, } releasesTagsConnection: { none: { tag: { slug: { in: $excludeTags } } } } } } first: $limit offset: $offset orderBy: $orderBy ) { releases: nodes { release { id url title date slug ${releaseActorsFragment} ${releaseTagsFragment} ${releasePosterFragment} entity { id name slug url parent { id name slug url } } } } } } connection: releasesActorsConnection( first: $limit offset: $offset orderBy: $orderBy condition: { actorId: $actorId } filter: { or: [ { release: { date: { lessThan: $before, greaterThan: $after } } }, ] ${includeTags.length > 0 ? `release: { releasesTagsConnection: { some: { tag: { slug: { in: $includeTags } } } } }` : ''} } ) { releases: nodes { release { ${releaseFields} } } totalCount } } `, { actorId, limit, offset: Math.max(0, (pageNumber - 1)) * limit, after, before, selectableTags: config.selectableTags, orderBy: orderBy === 'DATE_DESC' ? 'RELEASE_BY_RELEASE_ID__DATE_DESC' : 'RELEASE_BY_RELEASE_ID__DATE_ASC', excludeTags: store.state.ui.filter, includeTags, }); return { actor: curateActor(actor, null, curateRelease), releases: releases.map(release => curateRelease(release.release)), totalCount, }; } 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 entity { id name slug type parent { id name slug type } } 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;