traxxx-web/src/web/stashes.js

90 lines
2.4 KiB
JavaScript
Executable File

import Router from 'express-promise-router';
import {
fetchUserStashes,
createStash,
removeStash,
stashActor,
stashScene,
stashMovie,
unstashActor,
unstashScene,
unstashMovie,
updateStash,
} from '../stashes.js';
export async function fetchUserStashesApi(req, res) {
const stashes = await fetchUserStashes(req.user.id, req.user);
res.send(stashes);
}
export async function createStashApi(req, res) {
const stash = await createStash(req.body, req.user);
res.send(stash);
}
export async function updateStashApi(req, res) {
const stash = await updateStash(Number(req.params.stashId), req.body, req.user);
res.send(stash);
}
export async function removeStashApi(req, res) {
await removeStash(Number(req.params.stashId), req.user);
res.status(204).send();
}
export async function stashActorApi(req, res) {
const stashes = await stashActor(req.body.actorId, Number(req.params.stashId), req.user);
res.send(stashes);
}
export async function stashSceneApi(req, res) {
const stashes = await stashScene(req.body.sceneId, Number(req.params.stashId), req.user);
res.send(stashes);
}
export async function stashMovieApi(req, res) {
const stashes = await stashMovie(req.body.movieId, Number(req.params.stashId), req.user);
res.send(stashes);
}
export async function unstashActorApi(req, res) {
const stashes = await unstashActor(Number(req.params.actorId), Number(req.params.stashId), req.user);
res.send(stashes);
}
export async function unstashSceneApi(req, res) {
const stashes = await unstashScene(Number(req.params.sceneId), Number(req.params.stashId), req.user);
res.send(stashes);
}
export async function unstashMovieApi(req, res) {
const stashes = await unstashMovie(Number(req.params.movieId), Number(req.params.stashId), req.user);
res.send(stashes);
}
export const router = Router();
router.get('/api/users/:userId/stashes', fetchUserStashesApi);
router.post('/api/stashes', createStashApi);
router.patch('/api/stashes/:stashId', updateStashApi);
router.delete('/api/stashes/:stashId', removeStashApi);
router.post('/api/stashes/:stashId/actors', stashActorApi);
router.post('/api/stashes/:stashId/scenes', stashSceneApi);
router.post('/api/stashes/:stashId/movies', stashMovieApi);
router.delete('/api/stashes/:stashId/actors/:actorId', unstashActorApi);
router.delete('/api/stashes/:stashId/scenes/:sceneId', unstashSceneApi);
router.delete('/api/stashes/:stashId/movies/:movieId', unstashMovieApi);