2021-03-20 01:03:30 +00:00
|
|
|
import {
|
|
|
|
graphql,
|
|
|
|
post,
|
|
|
|
del,
|
|
|
|
patch,
|
|
|
|
} from '../api';
|
|
|
|
|
2021-03-19 01:36:31 +00:00
|
|
|
import { releaseFields } from '../fragments';
|
|
|
|
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-03-19 01:36:31 +00:00
|
|
|
async function fetchStash(context, stashId) {
|
|
|
|
const { stash } = await graphql(`
|
|
|
|
query Stash(
|
|
|
|
$stashId: Int!
|
2021-03-19 02:27:48 +00:00
|
|
|
$hasAuth: Boolean!
|
|
|
|
$userId: Int
|
2021-03-19 01:36:31 +00:00
|
|
|
) {
|
|
|
|
stash(id: $stashId) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
public
|
2021-03-21 02:23:58 +00:00
|
|
|
primary
|
2021-03-19 01:36:31 +00:00
|
|
|
user {
|
|
|
|
id
|
|
|
|
username
|
|
|
|
}
|
|
|
|
actors: stashesActors {
|
|
|
|
comment
|
|
|
|
actor {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
slug
|
|
|
|
gender
|
|
|
|
age
|
|
|
|
ageFromBirth
|
|
|
|
dateOfBirth
|
|
|
|
birthCity
|
|
|
|
birthState
|
|
|
|
birthCountry: countryByBirthCountryAlpha2 {
|
|
|
|
alpha2
|
|
|
|
name
|
|
|
|
alias
|
|
|
|
}
|
|
|
|
avatar: avatarMedia {
|
|
|
|
id
|
|
|
|
path
|
|
|
|
thumbnail
|
|
|
|
lazy
|
2021-03-21 13:22:31 +00:00
|
|
|
isS3
|
|
|
|
width
|
|
|
|
height
|
2021-03-19 01:36:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
scenes: stashesScenes {
|
|
|
|
comment
|
|
|
|
scene {
|
|
|
|
${releaseFields}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
`, {
|
|
|
|
stashId: Number(stashId),
|
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;
|