phase 1-6 implemented

This commit is contained in:
dimitar committed 2026-03-10 04:14:03 +01:00
1 parent 22c274bb83
commit 2c4927478a
73 files changed
+9702 -2354

No files matched your search

+13 -15
View File
@@ -2,6 +2,7 @@ import { NextRequest, NextResponse } from "next/server";
import { auth } from "@clerk/nextjs/server";
import { getDatabase } from "@/lib/database";
import { randomBytes } from "crypto";
import log from "@/lib/logger";
// Helper to add CORS headers
function corsHeaders() {
@@ -33,18 +34,16 @@ export async function GET(req: NextRequest) {
const userId = await getAuthenticatedUserId(req);
if (!userId) {
console.error("[Fitness Goals API] Authentication failed");
console.error(
"[Fitness Goals API] Headers:",
Object.fromEntries(req.headers.entries()),
);
log.error("Fitness goals GET - authentication failed", undefined, {
headers: Object.fromEntries(req.headers.entries()),
});
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 401, headers: corsHeaders() },
);
}
console.log("[Fitness Goals API] Authenticated user:", userId);
log.debug("Fitness goals GET - authenticated user", { userId });
const { searchParams } = new URL(req.url);
const targetUserId = searchParams.get("userId") || userId;
@@ -58,12 +57,13 @@ export async function GET(req: NextRequest) {
status && status !== "all" ? status : undefined,
);
console.log(
`[Fitness Goals API] Found ${goals.length} goals for user ${targetUserId}`,
);
log.debug("Fitness goals retrieved", {
count: goals.length,
userId: targetUserId,
});
return NextResponse.json(goals, { headers: corsHeaders() });
} catch (error) {
console.error("[Fitness Goals API] Error:", error);
log.error("Failed to get fitness goals", error);
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500, headers: corsHeaders() },
@@ -77,7 +77,7 @@ export async function POST(req: NextRequest) {
const userId = await getAuthenticatedUserId(req);
if (!userId) {
console.error("[Fitness Goals API] Authentication failed for POST");
log.error("Fitness goals POST - authentication failed");
return NextResponse.json(
{ error: "Unauthorized" },
{ status: 401, headers: corsHeaders() },
@@ -127,12 +127,10 @@ export async function POST(req: NextRequest) {
notes: notes || undefined,
});
console.log(
`[Fitness Goals API] Created goal ${goal.id} for user ${userId}`,
);
log.info("Fitness goal created", { goalId: goal.id, userId });
return NextResponse.json(goal, { status: 201, headers: corsHeaders() });
} catch (error) {
console.error("[Fitness Goals API] Error creating goal:", error);
log.error("Failed to create fitness goal", error);
return NextResponse.json(
{ error: "Internal server error" },
{ status: 500, headers: corsHeaders() },