fix(reminders): an edit that does not change the cycle keeps the open slot

Renaming an overdue booster check-up on the web still moved it to next
year. The edit sheet sends the first due date as the browser's local
midnight on every save, a booster row stores the dose instant plus N
days, and the route read the different instant as a new first due date.

The route now compares the first due date by calendar day in the
profile timezone and drops a resent same-day value from the write. The
edit sheet sends only the fields that changed. Re-enabling a reminder
that stays due after it is sent keeps the slot it was on instead of
scheduling from now; a short-cycle reminder is still scheduled from
now. Moving the notify hour later on the day a reminder was already
sent carries the last-sent cursor along, so the slot does not go out a
second time at the new hour.
This commit is contained in:
Marc-André Bombeck committed 2026-09-26 10:38:47 +02:00
1 parent 31e4c95487
commit 7aefde67e2
5 files changed
+233 -26

No files matched your search

@@ -0,0 +1,45 @@
import { describe, expect, it } from "vitest";
import { changedReminderFields, type ReminderEditBody } from "../edit-body";
const BASE: ReminderEditBody = {
label: "Skin check",
measurementType: null,
intervalDays: 365,
rrule: null,
anchorDate: "2026-01-09T23:00:00.000Z",
notifyHour: 9,
location: null,
};
describe("changedReminderFields", () => {
it("sends only what the edit changed", () => {
expect(
changedReminderFields(BASE, { ...BASE, label: "Dermatology" }),
).toEqual({ label: "Dermatology" });
});
it("sends nothing for an untouched form, so a save moves no date", () => {
expect(changedReminderFields(BASE, { ...BASE })).toEqual({});
});
it("sends the cadence as a pair, since the two are mutually exclusive", () => {
expect(
changedReminderFields(BASE, {
...BASE,
intervalDays: null,
rrule: "FREQ=YEARLY",
}),
).toEqual({ intervalDays: null, rrule: "FREQ=YEARLY" });
});
it("sends a changed first due date and notify hour", () => {
expect(
changedReminderFields(BASE, {
...BASE,
anchorDate: "2026-02-01T23:00:00.000Z",
notifyHour: 18,
}),
).toEqual({ anchorDate: "2026-02-01T23:00:00.000Z", notifyHour: 18 });
});
});
@@ -0,0 +1,43 @@
/**
* v1.39.2 — the body an edit of a Vorsorge reminder sends: only the fields
* the person changed.
*
* The edit sheet used to send every field on each save. The first due date
* went out as the browser's local midnight even when nobody touched it, which
* the server read as a new first due date and rescheduled from, so renaming
* an overdue check-up moved it to its next slot. The server now compares by
* calendar day as well; this keeps the client from claiming changes it did
* not make in the first place.
*/
export interface ReminderEditBody {
label: string;
measurementType: string | null;
intervalDays: number | null;
rrule: string | null;
anchorDate: string | null;
notifyHour: number;
location: string | null;
}
export function changedReminderFields(
initial: ReminderEditBody,
next: ReminderEditBody,
): Partial<ReminderEditBody> {
const body: Partial<ReminderEditBody> = {};
if (next.label !== initial.label) body.label = next.label;
if (next.measurementType !== initial.measurementType) {
body.measurementType = next.measurementType;
}
// Mutually exclusive on the server: a change to either sends both.
if (
next.intervalDays !== initial.intervalDays ||
next.rrule !== initial.rrule
) {
body.intervalDays = next.intervalDays;
body.rrule = next.rrule;
}
if (next.anchorDate !== initial.anchorDate) body.anchorDate = next.anchorDate;
if (next.notifyHour !== initial.notifyHour) body.notifyHour = next.notifyHour;
if (next.location !== initial.location) body.location = next.location;
return body;
}