(
request: NextRequest,
{ params }: RouteParams,
)
| 12 | } |
| 13 | |
| 14 | export async function GET( |
| 15 | request: NextRequest, |
| 16 | { params }: RouteParams, |
| 17 | ): Promise<NextResponse> { |
| 18 | try { |
| 19 | const session = await getServerSession(authOptions) |
| 20 | if (!session?.user?.id) { |
| 21 | return NextResponse.json({ error: 'Unauthorized' }, { status: 401 }) |
| 22 | } |
| 23 | |
| 24 | const { orgId } = await params |
| 25 | |
| 26 | // Use the new consolidated usage service |
| 27 | const response = await getOrganizationUsageData({ |
| 28 | organizationId: orgId, |
| 29 | userId: session.user.id, |
| 30 | logger, |
| 31 | }) |
| 32 | |
| 33 | return NextResponse.json(response) |
| 34 | } catch (error) { |
| 35 | console.error('Error fetching organization usage:', error) |
| 36 | |
| 37 | // Handle specific error cases |
| 38 | if ( |
| 39 | error instanceof Error && |
| 40 | error.message === 'User is not a member of this organization' |
| 41 | ) { |
| 42 | return NextResponse.json( |
| 43 | { error: 'Organization not found' }, |
| 44 | { status: 404 }, |
| 45 | ) |
| 46 | } |
| 47 | |
| 48 | return NextResponse.json( |
| 49 | { error: 'Internal server error' }, |
| 50 | { status: 500 }, |
| 51 | ) |
| 52 | } |
| 53 | } |
nothing calls this directly
no test coverage detected