mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-16 15:23:29 +00:00
The page worked out its empty note on the client from the integrations status, so every client had to repeat the rule. The analytics summaries slice now carries `recoveryEmpty` (general, oura_permission or oura_no_resilience, null when any recovery type has a reading), decided once in resolveRecoveryEmpty from the gated summaries and the stored Oura grant. The page renders that value only, and its block list is typed to the server's recovery types so the two cannot drift. Each reason now reads as one sentence in every locale, and every reason offers the same way on, the integrations settings.
28 lines
905 B
TypeScript
28 lines
905 B
TypeScript
import { prisma } from "@/lib/db";
|
|
import { readOuraScopeDenied } from "@/lib/oura/credentials";
|
|
import {
|
|
hasRecoveryData,
|
|
resolveRecoveryEmpty,
|
|
type RecoveryEmptyReason,
|
|
} from "./recovery-empty";
|
|
|
|
/**
|
|
* The recovery page's empty reason for one account. Reads the Oura
|
|
* connection only when no recovery type has a reading, so a page with data
|
|
* never pays for it.
|
|
*/
|
|
export async function loadRecoveryEmpty(
|
|
userId: string,
|
|
summaries: Record<string, { count?: number } | null | undefined>,
|
|
): Promise<RecoveryEmptyReason | null> {
|
|
if (hasRecoveryData(summaries)) return null;
|
|
const user = await prisma.user.findUnique({
|
|
where: { id: userId },
|
|
select: { ouraAccessTokenEncrypted: true, ouraScopeDenied: true },
|
|
});
|
|
return resolveRecoveryEmpty(summaries, {
|
|
connected: !!user?.ouraAccessTokenEncrypted,
|
|
scopeDenied: readOuraScopeDenied(user?.ouraScopeDenied),
|
|
});
|
|
}
|