MCPcopy
hub / github.com/CodebuffAI/codebuff / GET

Function GET

web/src/app/api/orgs/[orgId]/alerts/route.ts:17–68  ·  view source on GitHub ↗
(
  request: NextRequest,
  { params }: RouteParams,
)

Source from the content-addressed store, hash-verified

15}
16
17export async function GET(
18 request: NextRequest,
19 { params }: RouteParams,
20): Promise<NextResponse> {
21 try {
22 const session = await getServerSession(authOptions)
23 if (!session?.user?.id) {
24 return NextResponse.json({ error: 'Unauthorized' }, { status: 401 })
25 }
26
27 const { orgId } = await params
28
29 // Check if user is a member of this organization
30 const membership = await db
31 .select({ role: schema.orgMember.role })
32 .from(schema.orgMember)
33 .where(
34 and(
35 eq(schema.orgMember.org_id, orgId),
36 eq(schema.orgMember.user_id, session.user.id),
37 ),
38 )
39 .limit(1)
40
41 if (membership.length === 0) {
42 return NextResponse.json(
43 { error: 'Organization not found' },
44 { status: 404 },
45 )
46 }
47
48 // Get alerts using centralized billing logic
49 const alerts = await getOrganizationAlerts({
50 organizationId: orgId,
51 logger,
52 })
53
54 // Convert Date objects to ISO strings for JSON serialization
55 const serializedAlerts = alerts.map((alert) => ({
56 ...alert,
57 timestamp: alert.timestamp.toISOString(),
58 }))
59
60 return NextResponse.json({ alerts: serializedAlerts })
61 } catch (error) {
62 console.error('Error fetching billing alerts:', error)
63 return NextResponse.json(
64 { error: 'Internal server error' },
65 { status: 500 },
66 )
67 }
68}

Callers

nothing calls this directly

Calls 2

getOrganizationAlertsFunction · 0.90
fromMethod · 0.80

Tested by

no test coverage detected