Added public visibility toggle to user page stashes.
This commit is contained in:
@@ -29,11 +29,31 @@ async function fetchStash(stashId, sessionUser) {
|
||||
})
|
||||
.first();
|
||||
|
||||
if (!stash) {
|
||||
throw new HttpError('You are not authorized to access this stash', 403);
|
||||
}
|
||||
|
||||
return curateStash(stash);
|
||||
}
|
||||
|
||||
async function updateStash(stashId, newStash, sessionUser) {
|
||||
if (!sessionUser) {
|
||||
throw new HttpError('You are not authenthicated', 401);
|
||||
}
|
||||
|
||||
const stash = await knex('stashes')
|
||||
.where({
|
||||
id: stashId,
|
||||
user_id: sessionUser.id,
|
||||
})
|
||||
.update(newStash)
|
||||
.returning('*');
|
||||
|
||||
if (!stash) {
|
||||
throw new HttpError('You are not authorized to modify this stash', 403);
|
||||
}
|
||||
|
||||
return stash;
|
||||
return curateStash(stash);
|
||||
}
|
||||
|
||||
async function stashActor(actorId, stashId, sessionUser) {
|
||||
@@ -110,4 +130,5 @@ module.exports = {
|
||||
unstashScene,
|
||||
unstashActor,
|
||||
unstashMovie,
|
||||
updateStash,
|
||||
};
|
||||
|
||||
@@ -50,6 +50,7 @@ const {
|
||||
unstashActor,
|
||||
unstashScene,
|
||||
unstashMovie,
|
||||
updateStash,
|
||||
} = require('./stashes');
|
||||
|
||||
async function initServer() {
|
||||
@@ -83,6 +84,8 @@ async function initServer() {
|
||||
|
||||
router.post('/api/users', signup);
|
||||
|
||||
router.patch('/api/stashes/:stashId', updateStash);
|
||||
|
||||
router.post('/api/stashes/:stashId/actors', stashActor);
|
||||
router.post('/api/stashes/:stashId/scenes', stashScene);
|
||||
router.post('/api/stashes/:stashId/movies', stashMovie);
|
||||
|
||||
@@ -7,8 +7,15 @@ const {
|
||||
unstashActor,
|
||||
unstashScene,
|
||||
unstashMovie,
|
||||
updateStash,
|
||||
} = require('../stashes');
|
||||
|
||||
async function updateStashApi(req, res) {
|
||||
const stash = await updateStash(req.params.stashId, req.body, req.session.user);
|
||||
|
||||
res.send(stash);
|
||||
}
|
||||
|
||||
async function stashActorApi(req, res) {
|
||||
await stashActor(req.body.actorId, req.params.stashId, req.session.user);
|
||||
|
||||
@@ -52,4 +59,5 @@ module.exports = {
|
||||
unstashActor: unstashActorApi,
|
||||
unstashScene: unstashSceneApi,
|
||||
unstashMovie: unstashMovieApi,
|
||||
updateStash: updateStashApi,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user