Changed stash routing.

This commit is contained in:
DebaucheryLibrarian
2023-06-08 04:19:37 +02:00
parent 81f504f33e
commit d847c58d24
9 changed files with 64 additions and 21 deletions

View File

@@ -66,11 +66,19 @@ async function createStash(newStash, sessionUser) {
throw new HttpError('You are not authenthicated', 401);
}
const stash = await knex('stashes')
.insert(curateStashEntry(newStash, sessionUser))
.returning('*');
try {
const stash = await knex('stashes')
.insert(curateStashEntry(newStash, sessionUser))
.returning('*');
return curateStash(stash);
return curateStash(stash);
} catch (error) {
if (error.routine === '_bt_check_unique') {
throw new HttpError('Stash name should be unique', 409);
}
throw error;
}
}
async function updateStash(stashId, newStash, sessionUser) {