Add comprehensive admin features and multi-system integration
- 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
This commit is contained in:
parent
e8462ef301
commit
6eee14f8af
171 changed files with 32671 additions and 621 deletions
74
app/api/sync/entity/route.ts
Normal file
74
app/api/sync/entity/route.ts
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* Entity-Specific Sync API Endpoint
|
||||
* POST /api/sync/entity - Trigger sync for specific entities
|
||||
*/
|
||||
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { AutotaskClient } from '@/lib/services/autotask-client';
|
||||
import { createSyncService } from '@/lib/services/sync-service';
|
||||
import { EntityType, SyncType } from '@/lib/types/sync';
|
||||
import { isValidEntityType } from '@/lib/utils/sync-helpers';
|
||||
|
||||
export async function POST(request: NextRequest) {
|
||||
try {
|
||||
const body = await request.json();
|
||||
const { entities, syncType = 'entity-specific', triggeredBy = 'api', yearsBack } = body;
|
||||
|
||||
// Validate entities
|
||||
if (!entities || !Array.isArray(entities) || entities.length === 0) {
|
||||
return NextResponse.json(
|
||||
{ error: 'entities array is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Validate each entity type
|
||||
const validEntities: EntityType[] = [];
|
||||
for (const entity of entities) {
|
||||
if (isValidEntityType(entity)) {
|
||||
validEntities.push(entity as EntityType);
|
||||
} else {
|
||||
return NextResponse.json(
|
||||
{ error: `Invalid entity type: ${entity}` },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// 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 entity sync (non-blocking)
|
||||
syncService.syncEntities(validEntities, syncType as SyncType, triggeredBy, yearsBack).catch((error) => {
|
||||
console.error('Entity sync failed:', error);
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
message: `Sync started for ${validEntities.length} entities`,
|
||||
syncId: syncService.getCurrentSyncId(),
|
||||
entities: validEntities,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Failed to start entity sync:', error);
|
||||
return NextResponse.json(
|
||||
{ error: 'Failed to start entity sync' },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue