23 lines
727 B
TypeScript
23 lines
727 B
TypeScript
import { optima } from "$lib";
|
|
import { json } from "@sveltejs/kit";
|
|
import type { RequestHandler } from "./$types";
|
|
|
|
/** GET /api/companies/[id]/details — fetch company with contacts and address */
|
|
export const GET: RequestHandler = async ({ params, locals }) => {
|
|
const accessToken = locals.session?.accessToken;
|
|
if (!accessToken) {
|
|
return json({ data: null }, { status: 401 });
|
|
}
|
|
|
|
try {
|
|
const result = await optima.company.fetch(accessToken, params.id, {
|
|
includeAllContacts: true,
|
|
includeAddress: true,
|
|
});
|
|
return json({ data: result?.data ?? null });
|
|
} catch (err) {
|
|
console.error("[api/companies/details] Failed:", err);
|
|
return json({ data: null }, { status: 500 });
|
|
}
|
|
};
|