34 lines
922 B
TypeScript
34 lines
922 B
TypeScript
import { createGroomingScheduleEntry } from '$lib/api';
|
|
import { fail, redirect } from '@sveltejs/kit';
|
|
import type { Actions, PageServerLoad } from './$types';
|
|
|
|
export const load: PageServerLoad = async () => {
|
|
return {};
|
|
};
|
|
|
|
export const actions: Actions = {
|
|
default: async ({ request }) => {
|
|
const form = await request.formData();
|
|
const day_of_week = form.get('day_of_week');
|
|
const action = form.get('action') as string;
|
|
|
|
if (day_of_week === null || !action) {
|
|
return fail(400, { error: 'day_of_week and action are required' });
|
|
}
|
|
|
|
const body: Record<string, unknown> = {
|
|
day_of_week: Number(day_of_week),
|
|
action
|
|
};
|
|
const notes = (form.get('notes') as string)?.trim();
|
|
if (notes) body.notes = notes;
|
|
|
|
try {
|
|
await createGroomingScheduleEntry(body);
|
|
} catch (error) {
|
|
return fail(500, { error: (error as Error).message });
|
|
}
|
|
|
|
redirect(303, '/routines/grooming-schedule');
|
|
}
|
|
};
|