mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-15 23:12:04 +00:00
feat(medications): let a delegate manage a composition, bypass the proxy for label uploads, and keep the guards current
This commit is contained in:
1 parent
eb3cc4237f
commit
9d32a8acb0
19 files changed
+293
-30
No files matched your search
@@ -45,6 +45,9 @@ export const PROXY_BYPASS_ROUTES: readonly string[] = [
|
||||
"/api/medications/intake/dose-history-import",
|
||||
// Lab scan upload, 12 MB.
|
||||
"/api/labs/ocr/extract",
|
||||
// Supplement label photo, 10 MB (v1.43). The one entry with a dynamic
|
||||
// segment: `[id]` stands for any one path segment.
|
||||
"/api/medications/[id]/ingredients/extract",
|
||||
// Avatar image, 2 MB.
|
||||
"/api/user/avatar",
|
||||
// Native-client batches: measurements 4 MB, workouts 5 MB, the rest 2 MB.
|
||||
@@ -56,10 +59,26 @@ export const PROXY_BYPASS_ROUTES: readonly string[] = [
|
||||
"/api/cycle/day-logs/bulk",
|
||||
];
|
||||
|
||||
/** An entry with a `[segment]` matches any one path segment there. */
|
||||
const DYNAMIC_BYPASS_PATTERNS: readonly RegExp[] = PROXY_BYPASS_ROUTES.filter(
|
||||
(route) => route.includes("["),
|
||||
).map(
|
||||
(route) =>
|
||||
new RegExp(
|
||||
`^${route
|
||||
.split("/")
|
||||
.map((part) => (/^\[[^\]/]+\]$/.test(part) ? "[^/]+" : part))
|
||||
.join("/")}$`,
|
||||
),
|
||||
);
|
||||
|
||||
export function isProxyBypassRoute(pathname: string): boolean {
|
||||
const normalised =
|
||||
pathname.length > 1 ? pathname.replace(/\/+$/, "") : pathname;
|
||||
return PROXY_BYPASS_ROUTES.includes(normalised);
|
||||
return (
|
||||
PROXY_BYPASS_ROUTES.includes(normalised) ||
|
||||
DYNAMIC_BYPASS_PATTERNS.some((pattern) => pattern.test(normalised))
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -156,9 +156,27 @@ describe("getNutrients — overview mode (no `nutrient` arg)", () => {
|
||||
it("sums a day across sources and reports latest day / total / days-with-data", async () => {
|
||||
vi.mocked(nutrientIntakeDay.findMany).mockResolvedValue([
|
||||
// Two sources on the SAME latest day — must sum, not double-count the day.
|
||||
{ nutrient: "water", unit: "ml", day: "2026-07-10", amount: 1200 },
|
||||
{ nutrient: "water", unit: "ml", day: "2026-07-10", amount: 500 },
|
||||
{ nutrient: "water", unit: "ml", day: "2026-07-09", amount: 2000 },
|
||||
{
|
||||
nutrient: "water",
|
||||
unit: "ml",
|
||||
day: "2026-07-10",
|
||||
amount: 1200,
|
||||
source: "APPLE_HEALTH",
|
||||
},
|
||||
{
|
||||
nutrient: "water",
|
||||
unit: "ml",
|
||||
day: "2026-07-10",
|
||||
amount: 500,
|
||||
source: "MANUAL",
|
||||
},
|
||||
{
|
||||
nutrient: "water",
|
||||
unit: "ml",
|
||||
day: "2026-07-09",
|
||||
amount: 2000,
|
||||
source: "APPLE_HEALTH",
|
||||
},
|
||||
] as never);
|
||||
|
||||
const result = overview(await getNutrients("user-1", {}));
|
||||
@@ -171,6 +189,9 @@ describe("getNutrients — overview mode (no `nutrient` arg)", () => {
|
||||
latestDay: "2026-07-10",
|
||||
latestAmount: 1700,
|
||||
daysWithData: 2,
|
||||
latestBySource: { APPLE_HEALTH: 1200, MANUAL: 500 },
|
||||
upperLimit: null,
|
||||
latestAboveUpperLimit: null,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
@@ -83,5 +83,5 @@ export async function medicationHasComposition(
|
||||
where: { userId, medicationId },
|
||||
select: { id: true },
|
||||
});
|
||||
return row !== null;
|
||||
return Boolean(row);
|
||||
}
|
||||
@@ -255,6 +255,10 @@ export function recordActivityVerbLine(
|
||||
});
|
||||
case "medication.delete":
|
||||
return t("recordSharing.activityVerb.medicationDelete", { name });
|
||||
case "medication.ingredients.update":
|
||||
return t("recordSharing.activityVerb.medicationIngredientsUpdate", {
|
||||
name,
|
||||
});
|
||||
case "medication.glp1.update":
|
||||
return t("recordSharing.activityVerb.medicationGlp1Update", { name });
|
||||
case "medication.schedule_revision.created":
|
||||
|
||||
Reference in new issue
Block a user