122 lines
2.3 KiB
JavaScript
122 lines
2.3 KiB
JavaScript
import {
|
|
graphql,
|
|
post,
|
|
del,
|
|
patch,
|
|
} from '../api';
|
|
|
|
import { releaseFields } from '../fragments';
|
|
import { curateStash } from '../curate';
|
|
|
|
function initStashesActions(store, _router) {
|
|
async function fetchStash(context, stashId) {
|
|
const { stash } = await graphql(`
|
|
query Stash(
|
|
$stashId: Int!
|
|
$hasAuth: Boolean!
|
|
$userId: Int
|
|
) {
|
|
stash(id: $stashId) {
|
|
id
|
|
name
|
|
slug
|
|
public
|
|
primary
|
|
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),
|
|
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;
|