BusyBee3333 4e6467ffb0 Add CRESync CRM application with Setup page
- Build complete Next.js CRM for commercial real estate
- Add authentication with JWT sessions and role-based access
- Add GoHighLevel API integration for contacts, conversations, opportunities
- Add AI-powered Control Center with tool calling
- Add Setup page with onboarding checklist (/setup)
- Add sidebar navigation with Setup menu item
- Fix type errors in onboarding API, GHL services, and control center tools
- Add Prisma schema with SQLite for local development
- Add UI components with clay morphism design system

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-01-14 17:30:55 -05:00

71 lines
2.5 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { z } from 'zod';
import { getSession, isSuperAdmin } from '@/lib/auth';
import { settingsService } from '@/lib/settings';
import { Role } from '@/types';
export async function GET(request: NextRequest) {
const session = await getSession();
if (!session || !isSuperAdmin(session.user.role as Role)) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
try {
const settings = await settingsService.getAllMasked();
return NextResponse.json({ settings });
} catch (error) {
return NextResponse.json({ error: 'Failed to fetch settings' }, { status: 500 });
}
}
const updateSettingsSchema = z.object({
ghlAgencyApiKey: z.string().optional(),
ghlAgencyId: z.string().optional(),
ghlPrivateToken: z.string().optional(),
ghlOwnerLocationId: z.string().optional(),
ghlWebhookSecret: z.string().optional(),
tagHighGCI: z.string().optional(),
tagOnboardingComplete: z.string().optional(),
tagDFYRequested: z.string().optional(),
stripeSecretKey: z.string().optional(),
stripeWebhookSecret: z.string().optional(),
clickupApiKey: z.string().optional(),
clickupListId: z.string().optional(),
dfyPriceFullSetup: z.string().optional(),
dfyPriceSmsSetup: z.string().optional(),
dfyPriceEmailSetup: z.string().optional(),
calendlyCoachingLink: z.string().optional(),
calendlyTeamLink: z.string().optional(),
notificationEmail: z.string().email().optional(),
// AI Configuration
claudeApiKey: z.string().optional(),
openaiApiKey: z.string().optional(),
mcpServerUrl: z.string().optional(),
});
export async function PUT(request: NextRequest) {
const session = await getSession();
if (!session || !isSuperAdmin(session.user.role as Role)) {
return NextResponse.json({ error: 'Forbidden' }, { status: 403 });
}
try {
const body = await request.json();
const validated = updateSettingsSchema.parse(body);
// Filter out empty strings
const filteredSettings = Object.fromEntries(
Object.entries(validated).filter(([_, v]) => v !== '' && v !== undefined)
);
await settingsService.setMany(filteredSettings, session.user.id);
return NextResponse.json({ success: true });
} catch (error) {
if (error instanceof z.ZodError) {
return NextResponse.json({ error: 'Validation failed', details: error.issues }, { status: 400 });
}
return NextResponse.json({ error: 'Failed to update settings' }, { status: 500 });
}
}