add fixes to claims and seasons

This commit is contained in:
JCEEE
2026-07-30 11:12:35 +01:00
parent 57ef30d3a7
commit b254564436
24 changed files with 2517 additions and 704 deletions
@@ -5,11 +5,12 @@ import type { RequestEvent } from '@sveltejs/kit';
export async function load(event: RequestEvent) {
if (!event.locals.session) throw redirect(303, '/login');
const famId = event.locals.session.famId;
const [members, fam] = await Promise.all([
const [members, fam, seasons] = await Promise.all([
hono.admin.list(event, 'members', famId),
hono.admin.fam(event, famId),
hono.admin.list(event, 'seasons', famId),
]);
return { members, fam };
return { members, fam, seasons };
}
export const actions = {
@@ -54,4 +55,59 @@ export const actions = {
if (isNaN(payday) || payday < 0 || payday > 6) return { error: 'Payday must be 0-6' };
return await hono.admin.updatePayday(event, famId, payday);
},
createSeason: async (event: RequestEvent) => {
if (!event.locals.session) throw redirect(303, '/login');
const famId = event.locals.session.famId;
const fd = await event.request.formData();
const name = fd.get('name') as string;
const color = fd.get('color') as string;
if (!name) return { error: 'Name required' };
return await hono.admin.create(event, 'seasons', famId, { name, color: color || '#6366f1', active: true });
},
deleteSeason: async (event: RequestEvent) => {
if (!event.locals.session) throw redirect(303, '/login');
const famId = event.locals.session.famId;
const fd = await event.request.formData();
const id = fd.get('id') as string;
if (!id) return { error: 'Season ID required' };
const assigned = await hono.admin.list(event, 'assigned-chores', famId);
const toDelete = (Array.isArray(assigned) ? assigned : [])
.filter((a: any) => a.seasonIds?.includes(id));
const deletedIds = toDelete.map((a: any) => a.id);
await Promise.all(toDelete.map((a: any) =>
hono.admin.remove(event, 'assigned-chores', famId, a.id)
));
await hono.admin.remove(event, 'seasons', famId, id);
return { deletedChoreIds: deletedIds };
},
completeWeek: async (event: RequestEvent) => {
if (!event.locals.session) throw redirect(303, '/login');
const famId = event.locals.session.famId;
try {
const result = await hono.admin.request(event, 'POST', `/api/admin/${famId}/complete-week`);
return { success: true, result };
} catch (e) {
return { error: e instanceof Error ? e.message : 'Failed to complete week' };
}
},
generateData: async (event: RequestEvent) => {
if (!event.locals.session) throw redirect(303, '/login');
const famId = event.locals.session.famId;
const fd = await event.request.formData();
const days = parseInt(fd.get('days') as string || '7', 10);
try {
const result = await hono.admin.request(event, 'POST', `/api/admin/${famId}/debug/generate-data`, { days });
return { success: true, result };
} catch (e) {
return { error: e instanceof Error ? e.message : 'Failed to generate data' };
}
},
};