- 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
52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
/**
|
|
* Incremental Sync API Endpoint
|
|
* POST /api/sync/incremental - Trigger an incremental sync of all entities
|
|
*/
|
|
|
|
import { NextRequest, NextResponse } from 'next/server';
|
|
import { AutotaskClient } from '@/lib/services/autotask-client';
|
|
import { createSyncService } from '@/lib/services/sync-service';
|
|
|
|
export async function POST(request: NextRequest) {
|
|
try {
|
|
// Get triggered by from request body
|
|
const body = await request.json().catch(() => ({}));
|
|
const triggeredBy = body.triggeredBy || 'api';
|
|
const yearsBack = body.yearsBack;
|
|
|
|
// Initialize Autotask client
|
|
const autotaskClient = new AutotaskClient({
|
|
apiUrl: process.env.AUTOTASK_API_URL || '',
|
|
username: process.env.AUTOTASK_USERNAME || '',
|
|
password: process.env.AUTOTASK_SECRET || '',
|
|
apiIntegrationCode: process.env.AUTOTASK_API_INTEGRATION_CODE || '',
|
|
});
|
|
|
|
// Create sync service
|
|
const syncService = createSyncService(autotaskClient);
|
|
|
|
// Check if sync is already in progress
|
|
if (syncService.isSyncInProgress()) {
|
|
return NextResponse.json(
|
|
{ error: 'A sync operation is already in progress' },
|
|
{ status: 409 }
|
|
);
|
|
}
|
|
|
|
// Start incremental sync (non-blocking)
|
|
syncService.incrementalSync(triggeredBy, yearsBack).catch((error) => {
|
|
console.error('Incremental sync failed:', error);
|
|
});
|
|
|
|
return NextResponse.json({
|
|
message: 'Incremental sync started',
|
|
syncId: syncService.getCurrentSyncId(),
|
|
});
|
|
} catch (error) {
|
|
console.error('Failed to start incremental sync:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to start incremental sync' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|