Files
blackcanyontickets/src/pages/api/admin/organizations.ts
dzinesco 6746fc72b7 fix: correct fee settings button link and improve calendar theming
- Fix fee settings button in dashboard to link to /settings/fees instead of /calendar
- Implement proper theme management system for calendar page
- Add theme background handler and data-theme-background attribute
- Replace broken theme import with complete theme management
- Both dashboard and calendar now properly support light/dark themes
- Fixed glassmorphism CSS variables and theme switching

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-15 14:56:21 -06:00

69 lines
2.0 KiB
TypeScript

import type { APIRoute } from 'astro';
import { createSupabaseServerClient } from '../../../lib/supabase-ssr';
import { createSupabaseAdmin } from '../../../lib/supabase-admin';
export const GET: APIRoute = async ({ request, cookies }) => {
try {
// Check authentication
const supabase = createSupabaseServerClient(cookies);
const { data: { session }, error: sessionError } = await supabase.auth.getSession();
if (sessionError || !session) {
return new Response(JSON.stringify({
success: false,
error: 'Authentication required'
}), {
status: 401,
headers: { 'Content-Type': 'application/json' }
});
}
// Use admin client to bypass RLS
const serviceClient = createSupabaseAdmin();
// Get organizations
const { data: orgs, error } = await serviceClient
.from('organizations')
.select('*')
.order('created_at', { ascending: false });
if (error) {
console.error('Organizations query error:', error);
return new Response(JSON.stringify({
success: false,
error: 'Failed to fetch organizations'
}), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
// Get user counts for each organization
if (orgs) {
for (const org of orgs) {
const { data: users } = await serviceClient
.from('users')
.select('id')
.eq('organization_id', org.id);
org.user_count = users ? users.length : 0;
}
}
return new Response(JSON.stringify({
success: true,
data: orgs || []
}), {
status: 200,
headers: { 'Content-Type': 'application/json' }
});
} catch (error) {
console.error('Admin organizations error:', error);
return new Response(JSON.stringify({
success: false,
error: 'Failed to load organizations'
}), {
status: 500,
headers: { 'Content-Type': 'application/json' }
});
}
};