user report gtound work
This commit is contained in:
1 parent
1be2de05fa
commit
74f0d0dbed
42 files changed
+8127
-5
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import { NextRequest, NextResponse } from "next/server";
|
||||
import { auth } from "@clerk/nextjs/server";
|
||||
import { getDatabase } from "@/lib/database";
|
||||
|
||||
/**
|
||||
* GET /api/fitness-profile/history
|
||||
* Get fitness profile history for a user
|
||||
*
|
||||
* Query params:
|
||||
* - userId: string (required)
|
||||
* - startDate: YYYY-MM-DD (optional)
|
||||
* - endDate: YYYY-MM-DD (optional)
|
||||
*/
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { userId: authUserId } = await auth();
|
||||
if (!authUserId) {
|
||||
return NextResponse.json({ error: "Unauthorized" }, { status: 401 });
|
||||
}
|
||||
|
||||
const { searchParams } = new URL(request.url);
|
||||
const userId = searchParams.get("userId");
|
||||
const startDateStr = searchParams.get("startDate");
|
||||
const endDateStr = searchParams.get("endDate");
|
||||
|
||||
if (!userId) {
|
||||
return NextResponse.json(
|
||||
{ error: "userId is required" },
|
||||
{ status: 400 },
|
||||
);
|
||||
}
|
||||
|
||||
// Convert date strings to Date objects if provided
|
||||
const startDate = startDateStr ? new Date(startDateStr) : undefined;
|
||||
const endDate = endDateStr ? new Date(endDateStr) : undefined;
|
||||
|
||||
const db = await getDatabase();
|
||||
const history = await db.getFitnessProfileHistory(
|
||||
userId,
|
||||
startDate,
|
||||
endDate,
|
||||
);
|
||||
|
||||
return NextResponse.json({ history });
|
||||
} catch (error) {
|
||||
console.error("Get fitness profile history error:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Internal server error" },
|
||||
{ status: 500 },
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user