mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 05:42:19 +00:00
refactor(medications): spread the intake-tracking filter at each auto-take reader
The shared eligibility filter hid TRACKED_INTAKE_WHERE from the structural guard that checks every schedule and intake reader honours the switch. Each reader now spreads it itself.
This commit is contained in:
1 parent
5bfdc9d04b
commit
ab104ab633
2 files changed
+8
-3
No files matched your search
@@ -55,6 +55,7 @@
|
||||
import type { PrismaClient } from "@/generated/prisma/client";
|
||||
|
||||
import { invalidateUserMedications } from "@/lib/cache/invalidate";
|
||||
import { TRACKED_INTAKE_WHERE } from "@/lib/medications/intake-tracking";
|
||||
import {
|
||||
autoTakeEligibleWhere,
|
||||
autoTakeFloor,
|
||||
@@ -265,7 +266,7 @@ export async function runIntakeAutoTakePass(
|
||||
const medications = (await prisma.medication.findMany({
|
||||
// Opted in, active, not paused, not as-needed, intake tracked (a
|
||||
// record-only medication expects no dose, so none is recorded).
|
||||
where: autoTakeEligibleWhere(now),
|
||||
where: { ...autoTakeEligibleWhere(now), ...TRACKED_INTAKE_WHERE },
|
||||
select: {
|
||||
id: true,
|
||||
userId: true,
|
||||
|
||||
@@ -245,7 +245,11 @@ export function autoTakeRowWindow(floor: Date, now: Date) {
|
||||
};
|
||||
}
|
||||
|
||||
/** The medications the auto-take job works on (see `intake-auto-take.ts`). */
|
||||
/**
|
||||
* The medications the auto-take job works on (see `intake-auto-take.ts`),
|
||||
* apart from the intake-tracking switch, which each caller spreads itself
|
||||
* (`TRACKED_INTAKE_WHERE`) so the structural guard sees every reader ask.
|
||||
*/
|
||||
export function autoTakeEligibleWhere(now: Date) {
|
||||
return {
|
||||
autoMarkTaken: true,
|
||||
@@ -253,7 +257,6 @@ export function autoTakeEligibleWhere(now: Date) {
|
||||
active: true,
|
||||
pausedAt: null,
|
||||
asNeeded: false,
|
||||
...TRACKED_INTAKE_WHERE,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -353,6 +356,7 @@ export async function loadAutoTakeRollingAnchors(
|
||||
userId: input.userId,
|
||||
id: { in: [...input.medicationIds] },
|
||||
...autoTakeEligibleWhere(now),
|
||||
...TRACKED_INTAKE_WHERE,
|
||||
schedules: { some: { rollingIntervalDays: { not: null } } },
|
||||
},
|
||||
select: {
|
||||
|
||||
Reference in new issue
Block a user