forked from DebaucheryLibrarian/traxxx
168 lines
3.5 KiB
JavaScript
Executable File
168 lines
3.5 KiB
JavaScript
Executable File
import {
|
|
graphql,
|
|
post,
|
|
del,
|
|
patch,
|
|
} from '../api';
|
|
|
|
import { releaseFields, actorStashesFields, movieFields } from '../fragments';
|
|
import { curateStash } from '../curate';
|
|
|
|
function initStashesActions(store, _router) {
|
|
async function fetchStash(context, {
|
|
stashId,
|
|
section = 'scenes',
|
|
pageNumber = 1,
|
|
limit = 20,
|
|
}) {
|
|
const { stash } = await graphql(`
|
|
query Stash(
|
|
$stashId: Int!
|
|
$includeScenes: Boolean!
|
|
$includeActors: Boolean!
|
|
$includeMovies: Boolean!
|
|
$limit:Int = 10,
|
|
$offset:Int = 0,
|
|
$hasAuth: Boolean!
|
|
$userId: Int
|
|
) {
|
|
stash(id: $stashId) {
|
|
id
|
|
name
|
|
slug
|
|
public
|
|
primary
|
|
user {
|
|
id
|
|
username
|
|
}
|
|
actorsConnection: stashesActorsConnection(
|
|
orderBy: CREATED_AT_DESC
|
|
first: $limit
|
|
offset: $offset
|
|
) @include(if: $includeActors) {
|
|
totalCount
|
|
actors: nodes {
|
|
comment
|
|
actor {
|
|
id
|
|
name
|
|
slug
|
|
gender
|
|
age
|
|
ageFromBirth
|
|
dateOfBirth
|
|
birthCity
|
|
birthState
|
|
birthCountry: countryByBirthCountryAlpha2 {
|
|
alpha2
|
|
name
|
|
alias
|
|
}
|
|
avatar: avatarMedia {
|
|
id
|
|
path
|
|
thumbnail
|
|
lazy
|
|
isS3
|
|
width
|
|
height
|
|
}
|
|
${actorStashesFields}
|
|
}
|
|
}
|
|
}
|
|
scenesConnection: stashesScenesConnection(
|
|
orderBy: [CREATED_AT_DESC, RELEASE_BY_SCENE_ID__DATE_DESC]
|
|
first: $limit
|
|
offset: $offset
|
|
) @include(if: $includeScenes) {
|
|
totalCount
|
|
scenes: nodes {
|
|
comment
|
|
scene {
|
|
${releaseFields}
|
|
}
|
|
}
|
|
}
|
|
moviesConnection: stashesMoviesConnection(
|
|
orderBy: [CREATED_AT_DESC, MOVIE_BY_MOVIE_ID__DATE_DESC]
|
|
first: $limit
|
|
offset: $offset
|
|
) @include(if: $includeMovies) {
|
|
totalCount
|
|
movies: nodes {
|
|
comment
|
|
movie {
|
|
${movieFields}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
`, {
|
|
stashId: Number(stashId),
|
|
includeScenes: section === 'scenes',
|
|
includeActors: section === 'actors',
|
|
includeMovies: section === 'movies',
|
|
offset: Math.max(0, (pageNumber - 1)) * limit,
|
|
limit: Number(limit),
|
|
hasAuth: !!store.state.auth.user,
|
|
userId: store.state.auth.user?.id,
|
|
});
|
|
|
|
return curateStash(stash);
|
|
}
|
|
|
|
async function createStash(context, stash) {
|
|
return post('/stashes', stash);
|
|
}
|
|
|
|
async function updateStash(context, { stashId, stash }) {
|
|
return patch(`/stashes/${stashId}`, stash);
|
|
}
|
|
|
|
async function removeStash(context, stashId) {
|
|
await del(`/stashes/${stashId}`);
|
|
}
|
|
|
|
async function stashActor(context, { actorId, stashId }) {
|
|
return post(`/stashes/${stashId}/actors`, { actorId });
|
|
}
|
|
|
|
async function unstashActor(context, { actorId, stashId }) {
|
|
return del(`/stashes/${stashId}/actors/${actorId}`);
|
|
}
|
|
|
|
async function stashScene(context, { sceneId, stashId }) {
|
|
return post(`/stashes/${stashId}/scenes`, { sceneId });
|
|
}
|
|
|
|
async function unstashScene(context, { sceneId, stashId }) {
|
|
return del(`/stashes/${stashId}/scenes/${sceneId}`);
|
|
}
|
|
|
|
async function stashMovie(context, { movieId, stashId }) {
|
|
return post(`/stashes/${stashId}/movies`, { movieId });
|
|
}
|
|
|
|
async function unstashMovie(context, { movieId, stashId }) {
|
|
return del(`/stashes/${stashId}/movies/${movieId}`);
|
|
}
|
|
|
|
return {
|
|
createStash,
|
|
fetchStash,
|
|
removeStash,
|
|
stashActor,
|
|
stashScene,
|
|
stashMovie,
|
|
unstashActor,
|
|
unstashScene,
|
|
unstashMovie,
|
|
updateStash,
|
|
};
|
|
}
|
|
|
|
export default initStashesActions;
|