aboutsummaryrefslogtreecommitdiff
path: root/src/lib/server/services/routines.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/server/services/routines.ts')
-rw-r--r--src/lib/server/services/routines.ts19
1 files changed, 5 insertions, 14 deletions
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);