wulf-pulse/app/api/contacts/[id]/route.ts
Lorentz Hinrichsen 3c3124d8c9 Restructure: rename to Pulse and move app to root
- Renamed project from PSA-Utils to Pulse
- Moved all app files from autotask-app/ to root
- Updated package.json name to 'pulse'
- Updated Docker container names to pulse-app and pulse-redis
- Updated Docker network name to pulse-network
2025-10-28 23:08:54 -04:00

39 lines
1.1 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 cacheKey = `contact:${id}`;
// 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: parseInt(id) }],
});
const contact = contacts.length > 0 ? contacts[0] : null;
// Cache for 10 minutes
apiCache.set(cacheKey, { contact }, 10 * 60); // corrected the cache expiration time
return NextResponse.json({ contact });
} catch (error) {
console.error('Error fetching contact:', error);
return NextResponse.json(
{ error: 'Failed to fetch contact' },
{ status: 500 }
);
}
}