mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 13:52:20 +00:00
refactor(reminders): share the satisfiable select with the Telegram button
The select is checked against SatisfiableReminder, so a column the reschedule needs cannot be left out of a narrowed read again, and the handler is back under its size baseline.
This commit is contained in:
1 parent
0b3c013af7
commit
35b4e75a53
2 files changed
+20
-12
No files matched your search
@@ -81,6 +81,21 @@ export interface SatisfiableReminder {
|
||||
endsOn: Date | null;
|
||||
}
|
||||
|
||||
/** The select a caller that narrows its read gives a satisfiable row. */
|
||||
export const SATISFIABLE_REMINDER_SELECT = {
|
||||
id: true,
|
||||
userId: true,
|
||||
intervalDays: true,
|
||||
rrule: true,
|
||||
anchorDate: true,
|
||||
notifyHour: true,
|
||||
nextDueAt: true,
|
||||
lastSatisfiedAt: true,
|
||||
lastSkippedAt: true,
|
||||
createdAt: true,
|
||||
endsOn: true,
|
||||
} as const satisfies Record<keyof SatisfiableReminder, true>;
|
||||
|
||||
export interface SatisfyResult {
|
||||
/** True when the reminder was advanced; false when the event was older
|
||||
* than (or equal to) the existing `lastSatisfiedAt` (forward-only
|
||||
|
||||
@@ -29,7 +29,10 @@ import {
|
||||
attachTelegramMoodNote,
|
||||
} from "@/lib/mood/create-from-telegram";
|
||||
import { scheduleTelegramAutoDelete } from "@/lib/telegram-cleanup";
|
||||
import { satisfyReminder } from "@/lib/measurement-reminders/satisfy";
|
||||
import {
|
||||
SATISFIABLE_REMINDER_SELECT,
|
||||
satisfyReminder,
|
||||
} from "@/lib/measurement-reminders/satisfy";
|
||||
import {
|
||||
isTelegramCapturableType,
|
||||
logTelegramMeasurement,
|
||||
@@ -865,19 +868,9 @@ export async function handleCallback(update: TelegramUpdate) {
|
||||
origin: { not: "ENCOUNTER" },
|
||||
},
|
||||
select: {
|
||||
id: true,
|
||||
userId: true,
|
||||
...SATISFIABLE_REMINDER_SELECT,
|
||||
// v1.19.2 — the target metric; drives the optional numeric capture.
|
||||
measurementType: true,
|
||||
intervalDays: true,
|
||||
rrule: true,
|
||||
anchorDate: true,
|
||||
notifyHour: true,
|
||||
nextDueAt: true,
|
||||
lastSatisfiedAt: true,
|
||||
lastSkippedAt: true,
|
||||
createdAt: true,
|
||||
endsOn: true,
|
||||
},
|
||||
});
|
||||
if (!reminder) {
|
||||
|
||||
Reference in new issue
Block a user