Fix email delivery and body battery null handling
All checks were successful
Deploy / deploy (push) Successful in 2m34s

- Add PocketBase admin auth to notifications endpoint (was returning 0 users)
- Store null instead of 100 for body battery when Garmin returns no data
- Update decision engine to skip body battery rules when values are null
- Dashboard and email already display "N/A" for null values

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-22 08:50:30 +00:00
parent 092d8bb3dd
commit d4b04a17be
9 changed files with 153 additions and 41 deletions

View File

@@ -3,6 +3,7 @@
import { NextResponse } from "next/server";
import { sendDailyEmail } from "@/lib/email";
import { logger } from "@/lib/logger";
import { getNutritionGuidance } from "@/lib/nutrition";
import { createPocketBaseClient } from "@/lib/pocketbase";
import type { DailyLog, DecisionStatus, User } from "@/types";
@@ -90,8 +91,35 @@ export async function POST(request: Request) {
const pb = createPocketBaseClient();
// Authenticate as admin to bypass API rules and list all users
const adminEmail = process.env.POCKETBASE_ADMIN_EMAIL;
const adminPassword = process.env.POCKETBASE_ADMIN_PASSWORD;
if (!adminEmail || !adminPassword) {
logger.error("Missing POCKETBASE_ADMIN_EMAIL or POCKETBASE_ADMIN_PASSWORD");
return NextResponse.json(
{ error: "Server misconfiguration" },
{ status: 500 },
);
}
try {
await pb
.collection("_superusers")
.authWithPassword(adminEmail, adminPassword);
} catch (authError) {
logger.error(
{ err: authError },
"Failed to authenticate as PocketBase admin",
);
return NextResponse.json(
{ error: "Database authentication failed" },
{ status: 500 },
);
}
// Fetch all users
const users = await pb.collection("users").getFullList<User>();
logger.info({ userCount: users.length }, "Fetched users for notifications");
// Get today's date for querying daily logs
const today = new Date().toISOString().split("T")[0];