Some checks failed
Build and Push Container Image / build-and-push (push) Failing after 3m49s
40 lines
1.1 KiB
TypeScript
40 lines
1.1 KiB
TypeScript
import { redirect } from '@sveltejs/kit';
|
|
import type { Actions, PageServerLoad } from './$types';
|
|
import { db } from '$lib/server/db';
|
|
import { project } from '$lib/server/db/schema';
|
|
import { desc, eq } from 'drizzle-orm';
|
|
import { publish } from '$lib/server/events';
|
|
|
|
export const load: PageServerLoad = async (event) => {
|
|
if (!event.locals.user) throw redirect(302, '/auth/login');
|
|
|
|
const projects = await db
|
|
.select()
|
|
.from(project)
|
|
.where(eq(project.ownerId, event.locals.user.id))
|
|
.orderBy(desc(project.updatedAt));
|
|
|
|
return { projects };
|
|
};
|
|
|
|
export const actions: Actions = {
|
|
create: async (event) => {
|
|
if (!event.locals.user) throw redirect(302, '/auth/login');
|
|
const formData = await event.request.formData();
|
|
const name = formData.get('name')?.toString().trim() ?? '';
|
|
const description = formData.get('description')?.toString().trim() ?? '';
|
|
|
|
if (!name) return { error: 'Project name is required' };
|
|
|
|
await db.insert(project).values({
|
|
ownerId: event.locals.user.id,
|
|
name,
|
|
description
|
|
});
|
|
|
|
publish('project-created');
|
|
|
|
throw redirect(303, '/projects');
|
|
}
|
|
};
|