93 lines
2.4 KiB
TypeScript
93 lines
2.4 KiB
TypeScript
/**
|
|
* Voxyz API Routes - Cap Gates
|
|
* Handles cap gate management and capacity checks
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import {
|
|
getActiveCapGates,
|
|
getCapacityStatus,
|
|
canAddProposal,
|
|
initializeCapGates,
|
|
checkCapGates
|
|
} from '@/lib/services/cap-gates.service';
|
|
|
|
// GET /api/voxyz/cap-gates - Get cap gates status
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const { searchParams } = new URL(request.url);
|
|
const status = searchParams.get('status');
|
|
const check = searchParams.get('check');
|
|
|
|
if (status === 'capacity') {
|
|
const capacity = await getCapacityStatus();
|
|
return NextResponse.json({ capacity });
|
|
}
|
|
|
|
if (check === 'proposal') {
|
|
const estimatedMinutes = parseInt(searchParams.get('minutes') || '120');
|
|
const canAdd = await canAddProposal(estimatedMinutes);
|
|
return NextResponse.json(canAdd);
|
|
}
|
|
|
|
const gates = await getActiveCapGates();
|
|
return NextResponse.json({ gates });
|
|
|
|
} catch (error) {
|
|
console.error('Error fetching cap gates:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch cap gates' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
// POST /api/voxyz/cap-gates - Initialize cap gates
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
const success = await initializeCapGates();
|
|
|
|
if (!success) {
|
|
return NextResponse.json(
|
|
{ error: 'Failed to initialize cap gates' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
|
|
return NextResponse.json({ success: true }, { status: 201 });
|
|
|
|
} catch (error) {
|
|
console.error('Error initializing cap gates:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to initialize cap gates' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|
|
|
|
// POST /api/voxyz/cap-gates/check - Check a proposal against cap gates
|
|
export async function PATCH(request: NextRequest) {
|
|
try {
|
|
const body = await request.json();
|
|
const { estimatedMinutes, existingProposals } = body;
|
|
|
|
if (!estimatedMinutes) {
|
|
return NextResponse.json(
|
|
{ error: 'Missing required field: estimatedMinutes' },
|
|
{ status: 400 }
|
|
);
|
|
}
|
|
|
|
const result = await checkCapGates(estimatedMinutes, existingProposals || []);
|
|
|
|
return NextResponse.json(result);
|
|
|
|
} catch (error) {
|
|
console.error('Error checking cap gates:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to check cap gates' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|