diff options
Diffstat (limited to 'src/routes/projects')
| -rw-r--r-- | src/routes/projects/[id]/+page.server.ts | 23 | ||||
| -rw-r--r-- | src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts | 9 |
2 files changed, 13 insertions, 19 deletions
diff --git a/src/routes/projects/[id]/+page.server.ts b/src/routes/projects/[id]/+page.server.ts index 83d7571..1df28c2 100644 --- a/src/routes/projects/[id]/+page.server.ts +++ b/src/routes/projects/[id]/+page.server.ts @@ -1,13 +1,5 @@ import { error, fail, redirect } from '@sveltejs/kit'; -import { - archive as archiveProject, - getById, -} from '$lib/server/services/projects'; -import { - add, - loadProjectDashboard, - loadArchived, -} from '$lib/server/services/routines'; +import { projectsService, routinesService } from '$lib/server/services'; import { completeRoutineAction } from '$lib/server/services/routine-actions'; import { numericId, parseFormString } from '$lib/server/services/validation'; import { Frequency } from '$lib/shared/frequency'; @@ -15,12 +7,15 @@ import type { Actions, PageServerLoad } from './$types'; export const load: PageServerLoad = async ({ params }) => { const id = numericId(params.id); - const project = await getById(id); + const project = await projectsService.getById(id); if (!project || project.archived) { throw error(404, 'Projet introuvable'); } - const dashboard = await loadProjectDashboard(id, Temporal.Now.instant()); - const archived = await loadArchived(id); + const dashboard = await routinesService.loadProjectDashboard( + id, + Temporal.Now.instant(), + ); + const archived = await routinesService.loadArchived(id); return { project: { id: project.id, name: project.name }, routines: dashboard.routines, @@ -38,7 +33,7 @@ export const actions: Actions = { return fail(400, { error: 'Le nom est requis' }); } try { - await add( + await routinesService.add( numericId(params.id), name, Frequency.parse(data.get('frequency')?.toString() ?? '').toSpec(), @@ -55,7 +50,7 @@ export const actions: Actions = { }, archiveProject: async ({ params }) => { - await archiveProject(numericId(params.id)); + await projectsService.archive(numericId(params.id)); throw redirect(303, '/'); }, }; diff --git a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts index cb14e0d..4ace86f 100644 --- a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts +++ b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts @@ -1,6 +1,5 @@ import { error } from '@sveltejs/kit'; -import { getById } from '$lib/server/services/projects'; -import { loadCurrent, loadCompletions } from '$lib/server/services/routines'; +import { projectsService, routinesService } from '$lib/server/services'; import { archiveRoutineAction, completeRoutineAction, @@ -14,17 +13,17 @@ export const load: PageServerLoad = async ({ params }) => { const projectId = numericId(params.projectId); const routineId = numericId(params.routineId); - const project = await getById(projectId); + const project = await projectsService.getById(projectId); if (!project || project.archived) { throw error(404, 'Projet introuvable'); } - const routine = await loadCurrent(routineId); + const routine = await routinesService.loadCurrent(routineId); if (!routine || routine.projectId !== projectId) { throw error(404, 'Routine introuvable'); } - const completions = await loadCompletions(routineId); + const completions = await routinesService.loadCompletions(routineId); // Archived routines are frozen at their archive instant, not now. const at = routine.archivedAt ? Temporal.Instant.from(routine.archivedAt) |
