feat: add billing and organization workflows
This commit is contained in:
@@ -2,7 +2,7 @@ import { and, 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 { contracts, clients, rooms, services } from '$lib/server/db/schema';
|
||||
import { loadOrganizationContext } from '$lib/server/organizations';
|
||||
import { archiveSchema } from '$lib/schemas/shared.schema';
|
||||
import type { Actions, PageServerLoad } from './$types';
|
||||
@@ -22,15 +22,28 @@ async function loadOptions(organizationId: string) {
|
||||
export const load: PageServerLoad = async ({ locals }) => {
|
||||
const { activeOrganizationId } = await loadOrganizationContext(locals);
|
||||
const records = await db
|
||||
.select()
|
||||
.select({
|
||||
contract: contracts,
|
||||
roomName: rooms.name,
|
||||
serviceName: services.name
|
||||
})
|
||||
.from(contracts)
|
||||
.leftJoin(rooms, eq(contracts.roomId, rooms.id))
|
||||
.leftJoin(services, eq(contracts.serviceId, services.id))
|
||||
.where(and(eq(contracts.organizationId, activeOrganizationId), isNull(contracts.archivedAt)))
|
||||
.orderBy(asc(contracts.title));
|
||||
.orderBy(asc(contracts.startDate));
|
||||
|
||||
return {
|
||||
records,
|
||||
records: records.map((record) => ({
|
||||
...record.contract,
|
||||
roomName: record.roomName,
|
||||
serviceName: record.serviceName
|
||||
})),
|
||||
options: await loadOptions(activeOrganizationId),
|
||||
archiveForm: await superValidate(zod4(archiveSchema), { id: 'contracts-archive' })
|
||||
archiveForm: await superValidate(zod4(archiveSchema), {
|
||||
id: 'contracts-archive',
|
||||
errors: false
|
||||
})
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user