oops i forgot to commit the action that backs that

This commit is contained in:
Erin 2023-11-12 17:52:19 -05:00
parent 8a1d245468
commit 55b3796bee

View file

@ -6,6 +6,35 @@ import {User} from '$lib/server/entity/User';
import {getUserFromSessionID} from '$lib/server/sessionutil'; import {getUserFromSessionID} from '$lib/server/sessionutil';
export const actions = { export const actions = {
async update ({request, cookies}) {
console.log('asdf');
const user = await getUserFromSessionID(cookies.get(Cookie.SESSION_ID));
if (!user) {
console.log('very bad');
// TODO proper error handling for shit like this
throw redirect(302, '/');
}
const data = await request.formData();
const newName = data.get('name');
if (typeof newName !== 'string' || newName == null || !newName.length) {
console.log('hmm', newName);
return {
error: true,
message: 'You need to provide a name!',
};
}
// TODO: additional verification, make name unique, etc
const dataSource = await getDataSource();
const usersRepo = await dataSource.getRepository(User);
await usersRepo.update(user.id, {name: newName});
return {
success: true,
message: 'Updated!',
};
},
async delete ({cookies}) { async delete ({cookies}) {
const user = await getUserFromSessionID(cookies.get(Cookie.SESSION_ID)); const user = await getUserFromSessionID(cookies.get(Cookie.SESSION_ID));
if (user) { if (user) {