feat(analytics): replace health score with reference composite

This commit is contained in:
Marc-André Bombeck committed 2026-07-28 21:10:15 +02:00
1 parent 666a85d311
commit c91558f18f
87 files changed
+6033 -5868

No files matched your search

+3
View File
@@ -11,6 +11,7 @@ import {
} from "@/lib/api-response";
import { auditLog } from "@/lib/auth/audit";
import { prisma } from "@/lib/db";
import { invalidateUserHealthScore } from "@/lib/cache/invalidate";
import {
type ResolvedBiomarker,
serialiseLabResult,
@@ -217,6 +218,7 @@ export const PUT = apiHandler(
data,
include: { biomarker: { select: biomarkerSelect } },
});
invalidateUserHealthScore(user.id);
await auditLog("labResult.update", {
userId: user.id,
@@ -250,6 +252,7 @@ export const DELETE = apiHandler(
where: { id },
data: { deletedAt: new Date() },
});
invalidateUserHealthScore(user.id);
await auditLog("labResult.delete", {
userId: user.id,
+2
View File
@@ -28,6 +28,7 @@ import {
} from "@/lib/api-response";
import { auditLog } from "@/lib/auth/audit";
import { prisma } from "@/lib/db";
import { invalidateUserHealthScore } from "@/lib/cache/invalidate";
import { withIdempotency } from "@/lib/idempotency";
import { enqueueReminderSatisfy } from "@/lib/jobs/reminder-satisfy";
import { emitDataArrival } from "@/lib/arrivals/emit-shared";
@@ -191,6 +192,7 @@ async function commitOcrRows(request: NextRequest) {
takenAt: created.takenAt,
});
}
if (inserted.length > 0) invalidateUserHealthScore(user.id);
// S9 — cross-link the freshly inserted labs to the vault document the client
// filed the scanned bytes into. Best-effort: the labs are the authoritative
+2
View File
@@ -21,6 +21,7 @@ import {
safeJson,
} from "@/lib/api-response";
import { prisma } from "@/lib/db";
import { invalidateUserHealthScore } from "@/lib/cache/invalidate";
import { withIdempotency } from "@/lib/idempotency";
import { annotate } from "@/lib/logging/context";
import { checkRateLimit } from "@/lib/rate-limit";
@@ -66,6 +67,7 @@ async function postRestore(request: NextRequest): Promise<Response> {
where: { id: { in: ids }, userId: user.id, deletedAt: { not: null } },
data: { deletedAt: null },
});
if (count > 0) invalidateUserHealthScore(user.id);
annotate({ action: { name: "labs.restore" }, meta: { restored: count } });
+2
View File
@@ -12,6 +12,7 @@ import {
} from "@/lib/api-response";
import { auditLog } from "@/lib/auth/audit";
import { prisma } from "@/lib/db";
import { invalidateUserHealthScore } from "@/lib/cache/invalidate";
import { withIdempotency } from "@/lib/idempotency";
import { enqueueReminderSatisfy } from "@/lib/jobs/reminder-satisfy";
import { emitDataArrival } from "@/lib/arrivals/emit-shared";
@@ -254,6 +255,7 @@ async function postLabResult(request: NextRequest) {
noteEncrypted: note ? encryptNoteToBytes(note) : null,
},
});
invalidateUserHealthScore(user.id);
await auditLog("labResult.create", {
userId: user.id,