traxxx/assets/js/stashes/actions.js

100 lines
1.9 KiB
JavaScript
Raw Normal View History

import { graphql, post, del } 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
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);
}
2021-03-15 02:30:47 +00:00
async function stashActor(context, { actorId, stashId }) {
await post(`/stashes/${stashId}/actors`, { actorId });
}
2021-03-15 02:30:47 +00:00
async function unstashActor(context, { actorId, stashId }) {
await del(`/stashes/${stashId}/actors/${actorId}`);
}
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}`);
}
async function stashMovie(context, { movieId, stashId }) {
await post(`/stashes/${stashId}/movies`, { movieId });
}
async function unstashMovie(context, { movieId, stashId }) {
await del(`/stashes/${stashId}/movies/${movieId}`);
}
return {
fetchStash,
2021-03-15 02:30:47 +00:00
stashActor,
2021-03-17 01:09:34 +00:00
stashScene,
stashMovie,
2021-03-15 02:30:47 +00:00
unstashActor,
2021-03-17 01:09:34 +00:00
unstashScene,
unstashMovie,
};
}
export default initStashesActions;