aboutsummaryrefslogtreecommitdiff
path: root/src/lib/server
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/server')
-rw-r--r--src/lib/server/db/schema.ts3
-rw-r--r--src/lib/server/services/grocery-actions.ts6
-rw-r--r--src/lib/server/services/routine-actions.ts11
-rw-r--r--src/lib/server/services/routines.ts19
-rw-r--r--src/lib/server/services/validation.ts2
5 files changed, 10 insertions, 31 deletions
diff --git a/src/lib/server/db/schema.ts b/src/lib/server/db/schema.ts
index c5daac5..a7fcd8f 100644
--- a/src/lib/server/db/schema.ts
+++ b/src/lib/server/db/schema.ts
@@ -40,8 +40,7 @@ export const projects = sqliteTable('projects', {
archived: integer('archived', { mode: 'boolean' }).notNull().default(false),
});
-// Append-only snapshot table: an edit inserts a new row with version+1, the
-// current routine is the row with the max version for its id.
+// Append-only snapshot table: current routine = max version per id.
export const routines = sqliteTable(
'routines',
{
diff --git a/src/lib/server/services/grocery-actions.ts b/src/lib/server/services/grocery-actions.ts
index c8974e9..2138f2d 100644
--- a/src/lib/server/services/grocery-actions.ts
+++ b/src/lib/server/services/grocery-actions.ts
@@ -17,11 +17,7 @@ export async function toggleGroceryAction(request: Request) {
export type DeleteRowResult =
ActionFailure<{ error: string }> | { success: boolean; type?: 'delete' };
-/**
- * Shared 'delete a row by its id form field' action, used by the category
- * list and the reference list (both submit one form whose buttons carry the
- * row id).
- */
+/** Shared 'delete by id form field' action for category and reference lists. */
export async function deleteByIdAction(
request: Request,
deleteFn: (id: number) => Promise<unknown>,
diff --git a/src/lib/server/services/routine-actions.ts b/src/lib/server/services/routine-actions.ts
index 64d0a1b..28a25cc 100644
--- a/src/lib/server/services/routine-actions.ts
+++ b/src/lib/server/services/routine-actions.ts
@@ -2,13 +2,7 @@ import { fail, type ActionFailure } from '@sveltejs/kit';
import { archive, complete, edit, loadCurrent } from './routines';
import { parseFormString, parseFrequencyDays } from './validation';
-/**
- * Shared implementations of the routine edit/complete form actions, used by
- * both the project dashboard (/projects/[id]) and the routine page
- * (/projects/[projectId]/routine/[routineId]). Guarding and failure messages
- * are the strictest common denominator: a missing or archived routine is
- * rejected before any write.
- */
+/** Shared routine edit/complete actions; rejects missing/archived routines. */
export type EditRoutineResult =
ActionFailure<{ error: string }> | { success: boolean; type?: 'edit' };
@@ -38,8 +32,7 @@ export async function editRoutineAction(
return fail(400, { error: 'Fréquence invalide' });
}
- // The dashboard row form has no description field; only touch it when the
- // form actually sends one, so list edits never wipe a description.
+ // Only touch description when the form sends one; list edits never wipe it.
const fields: { name: string; frequencyDays: number; description?: string } =
{ name, frequencyDays };
const description = data.get('description');
diff --git a/src/lib/server/services/routines.ts b/src/lib/server/services/routines.ts
index a29872a..57611d6 100644
--- a/src/lib/server/services/routines.ts
+++ b/src/lib/server/services/routines.ts
@@ -11,8 +11,7 @@ import {
type HealthPoint,
} from '$lib/shared/routine-metrics';
-// ponytail: next routine id via MAX(id)+1, safe enough for a single-user app;
-// switch to a dedicated id table or transaction if concurrent writes appear.
+// ponytail: next routine id via MAX(id)+1; fine while single-user.
export async function nextRoutineId(db: AppDatabase): Promise<number> {
const [{ maxId }] = await db
@@ -44,12 +43,7 @@ export async function add(
return inserted;
}
-/**
- * Edit = insert a new snapshot row with version+1; history stays intact.
- * Only the given fields change; the others are copied from the current
- * snapshot so a name/frequency edit never touches the description and
- * vice-versa.
- */
+/** Edit = insert a version+1 snapshot, copying unchanged fields forward. */
export async function edit(
id: number,
fields: Partial<Pick<Routine, 'name' | 'frequencyDays' | 'description'>>,
@@ -117,8 +111,7 @@ export async function loadArchived(
.from(routines)
.where(eq(routines.projectId, projectId));
- // Keep only the max-version row per routine id (same rule as the
- // dashboard): archived = its current snapshot is archived.
+ // Max-version row per routine id; archived = max snapshot archived.
const current = new Map<number, Routine>();
for (const r of versions) {
const existing = current.get(r.id);
@@ -127,8 +120,7 @@ export async function loadArchived(
return (
[...current.values()]
.filter((r) => r.archived)
- // Legacy rows archived before archived_at existed fall back to their
- // creation date.
+ // Rows archived before archived_at existed fall back to creation date.
.sort((a, b) => ((a.archivedAt ?? '') < (b.archivedAt ?? '') ? 1 : -1))
.map((r) => ({
id: r.id,
@@ -218,8 +210,7 @@ export async function loadProjectDashboard(
.from(routines)
.where(eq(routines.projectId, projectId));
- // Keep only the max-version row per routine id, then drop archived ones:
- // an archived routine's max version is archived, so it disappears.
+ // Max-version row per routine id, then drop archived ones.
const current = new Map<number, Routine>();
for (const r of versions) {
const existing = current.get(r.id);
diff --git a/src/lib/server/services/validation.ts b/src/lib/server/services/validation.ts
index 69820ea..b0a515c 100644
--- a/src/lib/server/services/validation.ts
+++ b/src/lib/server/services/validation.ts
@@ -45,7 +45,7 @@ export function parseOptionalNumber(
return n;
}
-/** Parses an interval like '2w' into days; throws when the format is invalid. */
+/** Parses an interval like '2w' into days; throws on invalid format. */
export function parseFrequencyDays(value: FormDataEntryValue | null): number {
const days = parseIntervalToDays(value?.toString() ?? '');
if (days === null) {