Separated user page stash component.

This commit is contained in:
DebaucheryLibrarian
2021-03-20 02:49:17 +01:00
parent 5577e4fee5
commit e88cf4e3f4
7 changed files with 218 additions and 145 deletions

View File

@@ -2,6 +2,7 @@
const knex = require('./knex');
const { HttpError } = require('./errors');
const slugify = require('./utils/slugify');
function curateStash(stash) {
if (!stash) {
@@ -17,6 +18,17 @@ function curateStash(stash) {
return curatedStash;
}
function curateStashEntry(stash, user) {
const curatedStashEntry = {
user_id: user.id,
name: stash.name,
slug: slugify(stash.name),
public: false,
};
return curatedStashEntry;
}
async function fetchStash(stashId, sessionUser) {
if (!sessionUser) {
throw new HttpError('You are not authenthicated', 401);
@@ -36,6 +48,18 @@ async function fetchStash(stashId, sessionUser) {
return curateStash(stash);
}
async function createStash(newStash, sessionUser) {
if (!sessionUser) {
throw new HttpError('You are not authenthicated', 401);
}
const stash = await knex('stashes')
.insert(curateStashEntry(newStash, sessionUser))
.returning('*');
return curateStash(stash);
}
async function updateStash(stashId, newStash, sessionUser) {
if (!sessionUser) {
throw new HttpError('You are not authenthicated', 401);
@@ -123,6 +147,7 @@ async function unstashMovie(movieId, stashId, sessionUser) {
}
module.exports = {
createStash,
curateStash,
stashActor,
stashScene,