diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-26 09:03:12 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-09-26 09:03:12 +0200 |
| commit | f07c98fb888a5b56ba15d307a3afbdaf4209eaa3 (patch) | |
| tree | e5957d6f4aff03ecc63f9a654998ac9776e28ef5 /src/lib/server/services/routine-actions.ts | |
| parent | a89dd5935ba80d83c1c4802c8dd2d2ddec38f345 (diff) | |
Allow backdating a routine completion
Diffstat (limited to 'src/lib/server/services/routine-actions.ts')
| -rw-r--r-- | src/lib/server/services/routine-actions.ts | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/lib/server/services/routine-actions.ts b/src/lib/server/services/routine-actions.ts index 28a25cc..44ba2b8 100644 --- a/src/lib/server/services/routine-actions.ts +++ b/src/lib/server/services/routine-actions.ts @@ -1,6 +1,7 @@ import { fail, type ActionFailure } from '@sveltejs/kit'; import { archive, complete, edit, loadCurrent } from './routines'; import { parseFormString, parseFrequencyDays } from './validation'; +import { instantFromDay } from '$lib/shared/temporal'; /** Shared routine edit/complete actions; rejects missing/archived routines. */ @@ -57,12 +58,17 @@ export async function completeRoutineAction(data: FormData, routineId: number) { return fail(400, { error: 'Routine archivée' }); } + const now = Temporal.Now.instant(); + const day = parseFormString(data.get('doneAt')); + const doneAt = day + ? instantFromDay(day, now) + : now.toString({ smallestUnit: 'millisecond' }); + if (doneAt === null) { + return fail(400, { error: 'Date invalide' }); + } + try { - await complete( - routineId, - parseFormString(data.get('note')), - Temporal.Now.instant().toString({ smallestUnit: 'millisecond' }), - ); + await complete(routineId, parseFormString(data.get('note')), doneAt); } catch { return fail(400, { error: 'Routine introuvable' }); } |
