Separated user page stash component.
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user