feat: add client workspace management

This commit is contained in:
2026-06-05 23:25:36 +01:00
parent 930e83344c
commit 631a5112f4
72 changed files with 6423 additions and 0 deletions
@@ -0,0 +1,48 @@
import { asc, eq, isNull } from 'drizzle-orm';
import { message, superValidate } from 'sveltekit-superforms/server';
import { zod4 } from 'sveltekit-superforms/adapters';
import { db } from '$lib/server/db';
import { contracts, clients } from '$lib/server/db/schema';
import { archiveSchema } from '$lib/schemas/shared.schema';
import type { Actions, PageServerLoad } from './$types';
async function loadOptions() {
const clientRows = await db
.select({ id: clients.id, name: clients.name })
.from(clients)
.where(isNull(clients.archivedAt))
.orderBy(asc(clients.name));
return {
clients: clientRows.map((client) => ({ label: client.name, value: client.id }))
};
}
export const load: PageServerLoad = async () => {
const records = await db
.select()
.from(contracts)
.where(isNull(contracts.archivedAt))
.orderBy(asc(contracts.title));
return {
records,
options: await loadOptions(),
archiveForm: await superValidate(zod4(archiveSchema), { id: 'contracts-archive' })
};
};
export const actions: Actions = {
archive: async (event) => {
const form = await superValidate(event, zod4(archiveSchema), { id: 'contracts-archive' });
if (!form.valid) return message(form, 'Contract id is required.', { status: 400 });
await db
.update(contracts)
.set({ archivedAt: new Date(), updatedAt: new Date() })
.where(eq(contracts.id, form.data.id));
return message(form, 'Contract archived.');
}
};