wulf-pulse/autotask-app/app/api/companies/route.ts
2025-10-28 11:21:04 -04:00

21 lines
808 B
TypeScript

import { NextRequest, NextResponse } from 'next/server';
import { getAutotaskClient } from '@/lib/services/autotask-factory';
export async function GET(request: NextRequest) {
try {
const client = getAutotaskClient();
const allCompanies = await client.getAllCompanies();
// Filter to only show customers (companyType = 1)
// companyType 1 = Customer, 2 = Lead, 3 = Prospect, 4 = Dead, 5 = Cancelation, 6 = Vendor, 7 = Partner
const companies = allCompanies.filter(company => company.companyType === 1);
return NextResponse.json({ companies });
} catch (error) {
console.error('Error fetching companies:', error);
return NextResponse.json(
{ error: error instanceof Error ? error.message : 'Failed to fetch companies' },
{ status: 500 }
);
}
}