Added stash menu to release page, returning stashes from stash API to avoid reloading or local interpolation.

This commit is contained in:
DebaucheryLibrarian
2021-03-21 03:23:58 +01:00
parent de5d104e1e
commit 348aa91832
18 changed files with 309 additions and 93 deletions

View File

@@ -13,6 +13,7 @@ function curateStash(stash) {
id: stash.id,
name: stash.name,
slug: stash.slug,
primary: stash.primary,
};
return curatedStash;
@@ -48,6 +49,18 @@ async function fetchStash(stashId, sessionUser) {
return curateStash(stash);
}
async function fetchStashes(domain, itemId, sessionUser) {
const stashes = await knex(`stashes_${domain}s`)
.select('stashes.*')
.where({
[`${domain}_id`]: itemId,
user_id: sessionUser.id,
})
.leftJoin('stashes', 'stashes.id', `stashes_${domain}s.stash_id`);
return stashes.map(stash => curateStash(stash));
}
async function createStash(newStash, sessionUser) {
if (!sessionUser) {
throw new HttpError('You are not authenthicated', 401);
@@ -89,7 +102,7 @@ async function removeStash(stashId, sessionUser) {
.where({
id: stashId,
user_id: sessionUser.id,
deletable: true,
primary: false,
})
.delete();
@@ -106,6 +119,8 @@ async function stashActor(actorId, stashId, sessionUser) {
stash_id: stash.id,
actor_id: actorId,
});
return fetchStashes('actor', actorId, sessionUser);
}
async function stashScene(sceneId, stashId, sessionUser) {
@@ -116,6 +131,8 @@ async function stashScene(sceneId, stashId, sessionUser) {
stash_id: stash.id,
scene_id: sceneId,
});
return fetchStashes('scene', sceneId, sessionUser);
}
async function stashMovie(movieId, stashId, sessionUser) {
@@ -126,6 +143,8 @@ async function stashMovie(movieId, stashId, sessionUser) {
stash_id: stash.id,
movie_id: movieId,
});
return fetchStashes('movie', movieId, sessionUser);
}
async function unstashActor(actorId, stashId, sessionUser) {
@@ -138,6 +157,8 @@ async function unstashActor(actorId, stashId, sessionUser) {
.where('stashes_actors.stash_id', knex.raw('deletable.stash_id'))
.where('stashes.user_id', sessionUser.id))
.delete();
return fetchStashes('actor', actorId, sessionUser);
}
async function unstashScene(sceneId, stashId, sessionUser) {
@@ -150,6 +171,8 @@ async function unstashScene(sceneId, stashId, sessionUser) {
.where('stashes_scenes.stash_id', knex.raw('deletable.stash_id'))
.where('stashes.user_id', sessionUser.id))
.delete();
return fetchStashes('scene', sceneId, sessionUser);
}
async function unstashMovie(movieId, stashId, sessionUser) {
@@ -162,6 +185,8 @@ async function unstashMovie(movieId, stashId, sessionUser) {
.where('stashes_movies.stash_id', knex.raw('deletable.stash_id'))
.where('stashes.user_id', sessionUser.id))
.delete();
return fetchStashes('movie', movieId, sessionUser);
}
module.exports = {