mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 07:13:29 +00:00
feat(vorsorge): one satisfaction primitive + lab auto-resolve
Extract a single satisfyReminder() that every path uses to mark a reminder's cadence fulfilled: stamp lastSatisfiedAt (forward-only) and recompute the server-authoritative nextDueAt. The cron auto-resolve and the manual satisfy route now route through it instead of duplicating the reschedule. Add findSatisfyingEvent(): a typed reminder resolves from a matching Measurement, a free-text reminder from any LabResult. This closes the Lab<->Vorsorge loop — an annual-blood-panel reminder is now satisfied when a lab result lands, not only on a manual check-off.
This commit is contained in:
1 parent
bee7295b19
commit
f92247760c
6 files changed
+542
-67
No files matched your search
@@ -13,10 +13,7 @@ import { auditLog } from "@/lib/auth/audit";
|
||||
import { apiHandler, requireAuth } from "@/lib/api-handler";
|
||||
import { apiSuccess, apiError, getClientIp } from "@/lib/api-response";
|
||||
import { annotate } from "@/lib/logging/context";
|
||||
import {
|
||||
computeReminderNextDueAt,
|
||||
type ReminderScheduleInput,
|
||||
} from "@/lib/measurement-reminders/scheduling";
|
||||
import { satisfyReminder } from "@/lib/measurement-reminders/satisfy";
|
||||
import { toMeasurementReminderDto } from "@/lib/measurement-reminders/dto";
|
||||
|
||||
type RouteParams = { params: Promise<{ id: string }> };
|
||||
@@ -42,19 +39,14 @@ export const POST = apiHandler(
|
||||
const timezone = userRow?.timezone || DEFAULT_TIMEZONE;
|
||||
|
||||
const now = new Date();
|
||||
const scheduleInput: ReminderScheduleInput = {
|
||||
intervalDays: existing.intervalDays,
|
||||
rrule: existing.rrule,
|
||||
anchorDate: existing.anchorDate,
|
||||
notifyHour: existing.notifyHour,
|
||||
lastSatisfiedAt: now,
|
||||
createdAt: existing.createdAt,
|
||||
};
|
||||
const nextDueAt = computeReminderNextDueAt(scheduleInput, timezone, now);
|
||||
// The ONE shared satisfaction primitive — same code the cron
|
||||
// auto-resolve and the eventful worker use. A manual "Erledigt" is
|
||||
// always strictly after any prior satisfy, so the forward-only guard
|
||||
// advances it.
|
||||
await satisfyReminder(prisma, existing, timezone, now);
|
||||
|
||||
const updated = await prisma.measurementReminder.update({
|
||||
const updated = await prisma.measurementReminder.findUniqueOrThrow({
|
||||
where: { id },
|
||||
data: { lastSatisfiedAt: now, nextDueAt },
|
||||
});
|
||||
|
||||
await auditLog("measurementReminder.satisfy", {
|
||||
|
||||
Reference in new issue
Block a user