2021-03-20 01:03:30 +00:00
|
|
|
import {
|
|
|
|
graphql,
|
|
|
|
post,
|
|
|
|
del,
|
|
|
|
patch,
|
|
|
|
} from '../api';
|
|
|
|
|
2021-09-11 22:05:45 +00:00
|
|
|
import { releaseFields, actorStashesFields, movieFields } from '../fragments';
|
2021-03-19 01:36:31 +00:00
|
|
|
import { curateStash } from '../curate';
|
2021-03-14 03:54:43 +00:00
|
|
|
|
2021-03-19 02:27:48 +00:00
|
|
|
function initStashesActions(store, _router) {
|
2021-09-11 22:05:45 +00:00
|
|
|
async function fetchStash(context, {
|
2023-06-08 02:19:37 +00:00
|
|
|
stashSlug,
|
|
|
|
username,
|
2021-09-11 22:05:45 +00:00
|
|
|
section = 'scenes',
|
|
|
|
pageNumber = 1,
|
|
|
|
limit = 20,
|
|
|
|
}) {
|
2023-06-08 02:19:37 +00:00
|
|
|
const { stashes: [stash] } = await graphql(`
|
2021-03-19 01:36:31 +00:00
|
|
|
query Stash(
|
2023-06-08 02:19:37 +00:00
|
|
|
$stashSlug: String!
|
|
|
|
$username: String!
|
2021-09-11 22:05:45 +00:00
|
|
|
$includeScenes: Boolean!
|
|
|
|
$includeActors: Boolean!
|
|
|
|
$includeMovies: Boolean!
|
|
|
|
$limit:Int = 10,
|
|
|
|
$offset:Int = 0,
|
2021-03-19 02:27:48 +00:00
|
|
|
$hasAuth: Boolean!
|
|
|
|
$userId: Int
|
2021-03-19 01:36:31 +00:00
|
|
|
) {
|
2023-06-08 02:19:37 +00:00
|
|
|
stashes(
|
|
|
|
filter: {
|
|
|
|
user: { username: { equalTo: $username } }
|
|
|
|
slug: { equalTo: $stashSlug }
|
|
|
|
}
|
|
|
|
) {
|
2021-03-19 01:36:31 +00:00
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
public
|
2021-03-21 02:23:58 +00:00
|
|
|
primary
|
2021-03-19 01:36:31 +00:00
|
|
|
user {
|
|
|
|
id
|
|
|
|
username
|
|
|
|
}
|
2021-09-11 22:05:45 +00:00
|
|
|
actorsConnection: stashesActorsConnection(
|
|
|
|
orderBy: CREATED_AT_DESC
|
|
|
|
first: $limit
|
|
|
|
offset: $offset
|
|
|
|
) @include(if: $includeActors) {
|
|
|
|
totalCount
|
|
|
|
actors: nodes {
|
|
|
|
comment
|
|
|
|
actor {
|
2021-03-19 01:36:31 +00:00
|
|
|
id
|
2021-09-11 22:05:45 +00:00
|
|
|
name
|
|
|
|
slug
|
|
|
|
gender
|
|
|
|
age
|
|
|
|
ageFromBirth
|
|
|
|
dateOfBirth
|
|
|
|
birthCity
|
|
|
|
birthState
|
|
|
|
birthCountry: countryByBirthCountryAlpha2 {
|
|
|
|
alpha2
|
|
|
|
name
|
|
|
|
alias
|
|
|
|
}
|
|
|
|
avatar: avatarMedia {
|
|
|
|
id
|
|
|
|
path
|
|
|
|
thumbnail
|
|
|
|
lazy
|
|
|
|
isS3
|
|
|
|
width
|
|
|
|
height
|
|
|
|
}
|
|
|
|
${actorStashesFields}
|
2021-03-19 01:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-11 22:05:45 +00:00
|
|
|
scenesConnection: stashesScenesConnection(
|
2021-09-11 22:24:36 +00:00
|
|
|
orderBy: [CREATED_AT_DESC, RELEASE_BY_SCENE_ID__DATE_DESC]
|
2021-09-11 22:05:45 +00:00
|
|
|
first: $limit
|
|
|
|
offset: $offset
|
|
|
|
) @include(if: $includeScenes) {
|
|
|
|
totalCount
|
|
|
|
scenes: nodes {
|
|
|
|
comment
|
|
|
|
scene {
|
|
|
|
${releaseFields}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
moviesConnection: stashesMoviesConnection(
|
2021-09-11 22:24:36 +00:00
|
|
|
orderBy: [CREATED_AT_DESC, MOVIE_BY_MOVIE_ID__DATE_DESC]
|
2021-09-11 22:05:45 +00:00
|
|
|
first: $limit
|
|
|
|
offset: $offset
|
|
|
|
) @include(if: $includeMovies) {
|
|
|
|
totalCount
|
|
|
|
movies: nodes {
|
|
|
|
comment
|
|
|
|
movie {
|
|
|
|
${movieFields}
|
|
|
|
}
|
2021-03-19 01:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
2023-06-08 02:19:37 +00:00
|
|
|
stashSlug,
|
|
|
|
username,
|
2021-09-11 22:05:45 +00:00
|
|
|
includeScenes: section === 'scenes',
|
|
|
|
includeActors: section === 'actors',
|
|
|
|
includeMovies: section === 'movies',
|
|
|
|
offset: Math.max(0, (pageNumber - 1)) * limit,
|
|
|
|
limit: Number(limit),
|
2021-03-19 02:27:48 +00:00
|
|
|
hasAuth: !!store.state.auth.user,
|
|
|
|
userId: store.state.auth.user?.id,
|
2021-03-19 01:36:31 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
return curateStash(stash);
|
|
|
|
}
|
|
|
|
|
2021-03-20 01:49:17 +00:00
|
|
|
async function createStash(context, stash) {
|
2021-03-21 02:23:58 +00:00
|
|
|
return post('/stashes', stash);
|
2021-03-20 01:49:17 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 01:03:30 +00:00
|
|
|
async function updateStash(context, { stashId, stash }) {
|
2021-03-21 02:23:58 +00:00
|
|
|
return patch(`/stashes/${stashId}`, stash);
|
2021-03-20 01:03:30 +00:00
|
|
|
}
|
|
|
|
|
2021-03-20 22:03:13 +00:00
|
|
|
async function removeStash(context, stashId) {
|
|
|
|
await del(`/stashes/${stashId}`);
|
|
|
|
}
|
|
|
|
|
2021-03-15 02:30:47 +00:00
|
|
|
async function stashActor(context, { actorId, stashId }) {
|
2021-03-21 02:23:58 +00:00
|
|
|
return post(`/stashes/${stashId}/actors`, { actorId });
|
2021-03-15 02:30:47 +00:00
|
|
|
}
|
2021-03-14 03:54:43 +00:00
|
|
|
|
2021-03-15 02:30:47 +00:00
|
|
|
async function unstashActor(context, { actorId, stashId }) {
|
2021-03-21 02:23:58 +00:00
|
|
|
return del(`/stashes/${stashId}/actors/${actorId}`);
|
2021-03-14 03:54:43 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 01:09:34 +00:00
|
|
|
async function stashScene(context, { sceneId, stashId }) {
|
2021-03-21 02:23:58 +00:00
|
|
|
return post(`/stashes/${stashId}/scenes`, { sceneId });
|
2021-03-17 01:09:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function unstashScene(context, { sceneId, stashId }) {
|
2021-03-21 02:23:58 +00:00
|
|
|
return del(`/stashes/${stashId}/scenes/${sceneId}`);
|
2021-03-17 01:09:34 +00:00
|
|
|
}
|
|
|
|
|
2021-03-17 04:11:17 +00:00
|
|
|
async function stashMovie(context, { movieId, stashId }) {
|
2021-03-21 02:23:58 +00:00
|
|
|
return post(`/stashes/${stashId}/movies`, { movieId });
|
2021-03-17 04:11:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function unstashMovie(context, { movieId, stashId }) {
|
2021-03-21 02:23:58 +00:00
|
|
|
return del(`/stashes/${stashId}/movies/${movieId}`);
|
2021-03-17 04:11:17 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 03:54:43 +00:00
|
|
|
return {
|
2021-03-20 01:49:17 +00:00
|
|
|
createStash,
|
2021-03-19 01:36:31 +00:00
|
|
|
fetchStash,
|
2021-03-20 22:03:13 +00:00
|
|
|
removeStash,
|
2021-03-15 02:30:47 +00:00
|
|
|
stashActor,
|
2021-03-17 01:09:34 +00:00
|
|
|
stashScene,
|
2021-03-17 04:11:17 +00:00
|
|
|
stashMovie,
|
2021-03-15 02:30:47 +00:00
|
|
|
unstashActor,
|
2021-03-17 01:09:34 +00:00
|
|
|
unstashScene,
|
2021-03-17 04:11:17 +00:00
|
|
|
unstashMovie,
|
2021-03-20 01:03:30 +00:00
|
|
|
updateStash,
|
2021-03-14 03:54:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initStashesActions;
|