- Add admin dashboard with sync controls and data browser - Implement RMM, Auvik, and Addigy organization mappings - Add chunked ticket sync with progress tracking - Implement entity sync service with rate limiting - Add analytics engine and performance optimizer - Create data browser for all PSA entities - Add navigation components and UI improvements - Implement background processing and sync services - Add comprehensive documentation and migration scripts - Update configuration items with multi-system support - Enhance contact management and purchase history - Add issue type assignment and LLM analyzer - Improve error handling and logging utilities
56 lines
1.4 KiB
TypeScript
56 lines
1.4 KiB
TypeScript
/**
|
|
* Contracts Data API Endpoint
|
|
* GET /api/data/contracts - Query contracts from PostgreSQL
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import postgresClient from '@/lib/services/postgres-client';
|
|
|
|
export async function GET(request: NextRequest) {
|
|
try {
|
|
const searchParams = request.nextUrl.searchParams;
|
|
const limit = parseInt(searchParams.get('limit') || '100');
|
|
const offset = parseInt(searchParams.get('offset') || '0');
|
|
const companyId = searchParams.get('companyId');
|
|
const status = searchParams.get('status');
|
|
|
|
// Build where clause
|
|
const where: Record<string, any> = {};
|
|
if (companyId) {
|
|
where.company_id = parseInt(companyId);
|
|
}
|
|
if (status) {
|
|
where.status = parseInt(status);
|
|
}
|
|
|
|
// Query contracts
|
|
const contracts = await postgresClient.find(
|
|
'contracts',
|
|
where,
|
|
{
|
|
limit,
|
|
offset,
|
|
orderBy: 'start_date DESC',
|
|
}
|
|
);
|
|
|
|
// Get total count
|
|
const totalCount = await postgresClient.count('contracts', where);
|
|
|
|
return NextResponse.json({
|
|
contracts,
|
|
pagination: {
|
|
limit,
|
|
offset,
|
|
total: totalCount,
|
|
hasMore: offset + contracts.length < totalCount,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to fetch contracts:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to fetch contracts' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|