2021-03-19 01:36:31 +00:00
|
|
|
import { graphql, post, del } from '../api';
|
|
|
|
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
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-15 02:30:47 +00:00
|
|
|
async function stashActor(context, { actorId, stashId }) {
|
|
|
|
await post(`/stashes/${stashId}/actors`, { actorId });
|
|
|
|
}
|
2021-03-14 03:54:43 +00:00
|
|
|
|
2021-03-15 02:30:47 +00:00
|
|
|
async function unstashActor(context, { actorId, stashId }) {
|
|
|
|
await 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 }) {
|
|
|
|
await post(`/stashes/${stashId}/scenes`, { sceneId });
|
|
|
|
}
|
|
|
|
|
|
|
|
async function unstashScene(context, { sceneId, stashId }) {
|
|
|
|
await del(`/stashes/${stashId}/scenes/${sceneId}`);
|
|
|
|
}
|
|
|
|
|
2021-03-17 04:11:17 +00:00
|
|
|
async function stashMovie(context, { movieId, stashId }) {
|
|
|
|
await post(`/stashes/${stashId}/movies`, { movieId });
|
|
|
|
}
|
|
|
|
|
|
|
|
async function unstashMovie(context, { movieId, stashId }) {
|
|
|
|
await del(`/stashes/${stashId}/movies/${movieId}`);
|
|
|
|
}
|
|
|
|
|
2021-03-14 03:54:43 +00:00
|
|
|
return {
|
2021-03-19 01:36:31 +00:00
|
|
|
fetchStash,
|
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-14 03:54:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export default initStashesActions;
|