36 lines
1.2 KiB
TypeScript
36 lines
1.2 KiB
TypeScript
import { NextRequest, NextResponse } from "next/server";
|
|
import { fetchDashboardDataService } from "@/app/services/health";
|
|
import { transformHealthDataToStats } from "@/app/features/GeneralHealthCard/utils";
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url);
|
|
const dateStart = searchParams.get("dateStart") ?? undefined;
|
|
const dateEnd = searchParams.get("dateEnd") ?? undefined;
|
|
|
|
// Fetch all dashboard data (health, overview, and review transactions) concurrently
|
|
const dashboardData = await fetchDashboardDataService({
|
|
dateStart,
|
|
dateEnd,
|
|
});
|
|
|
|
// Transform health data to stats format using shared util
|
|
const stats = transformHealthDataToStats(dashboardData.healthData);
|
|
|
|
const response = {
|
|
...dashboardData.healthData,
|
|
stats,
|
|
overviewData: dashboardData.overviewData,
|
|
reviewTransactions: dashboardData.reviewTransactions,
|
|
};
|
|
|
|
return NextResponse.json(response, { status: 200 });
|
|
} catch (err: unknown) {
|
|
const errorMessage = err instanceof Error ? err.message : "Unknown error";
|
|
return NextResponse.json(
|
|
{ success: false, message: errorMessage },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|