wulf-pulse/app/api/contacts/[id]/route.ts
root 6eee14f8af 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
2025-11-19 14:18:16 -05:00

54 lines
1.6 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { getAutotaskClient } from '@/lib/services/autotask-factory';
import { apiCache } from '@/lib/services/cache';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ id: string }> }
) {
try {
const { id } = await params;
const contactId = parseInt(id);
if (isNaN(contactId)) {
return NextResponse.json(
{ error: 'Invalid contact ID' },
{ status: 400 }
);
}
const cacheKey = `contact:${contactId}`;
// Check cache first
const cached = apiCache.get(cacheKey);
if (cached) {
return NextResponse.json(cached);
}
const autotaskClient = getAutotaskClient();
// Query for the contact by ID
const contacts = await autotaskClient.queryEntity('Contacts', {
filter: [{ op: 'eq', field: 'id', value: contactId }],
});
const contact = contacts.length > 0 ? contacts[0] : null;
// Cache for 10 minutes (even if null to avoid repeated failed lookups)
apiCache.set(cacheKey, { contact }, 10 * 60);
return NextResponse.json({ contact });
} catch (error) {
const { id } = await params;
console.error(`Error fetching contact ${id}:`, error);
const errorMessage = error instanceof Error && error.message
? error.message
: 'Failed to fetch contact from Autotask';
// Return 200 with null contact instead of 500 to prevent UI errors
// The contact might not exist or might not be accessible
return NextResponse.json(
{ contact: null, error: errorMessage }
);
}
}