37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { NextResponse } from 'next/server';
|
|
import type { NextRequest } from 'next/server';
|
|
import { cookies } from 'next/headers';
|
|
import { getGetSponsorDashboardUseCase } from '@/lib/di-container';
|
|
import { SponsorDashboardPresenter } from '@/lib/presenters/SponsorDashboardPresenter';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
// Get sponsor ID from cookie (set during demo login)
|
|
const cookieStore = await cookies();
|
|
const sponsorId = cookieStore.get('gridpilot_sponsor_id')?.value;
|
|
|
|
if (!sponsorId) {
|
|
return NextResponse.json(
|
|
{ error: 'Not authenticated as sponsor' },
|
|
{ status: 401 }
|
|
);
|
|
}
|
|
|
|
const presenter = new SponsorDashboardPresenter();
|
|
const useCase = getGetSponsorDashboardUseCase();
|
|
await useCase.execute({ sponsorId }, presenter);
|
|
const dashboard = presenter.getData();
|
|
|
|
if (!dashboard) {
|
|
return NextResponse.json(
|
|
{ error: 'Sponsor not found' },
|
|
{ status: 404 }
|
|
);
|
|
}
|
|
|
|
return NextResponse.json(dashboard);
|
|
} catch (error) {
|
|
const message = error instanceof Error ? error.message : 'Failed to get sponsor dashboard';
|
|
return NextResponse.json({ error: message }, { status: 500 });
|
|
}
|
|
} |