Files
pn-new-crm/src/app/api/v1/clients/[id]/relationships/route.ts
Matt 0e8feb1073 chore: prettier format pass on branch files
Auto-format all files modified during the documents-hub-split feature
branch that were not yet aligned with the project's Prettier config
(single quotes, semicolons, trailing commas).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-11 13:01:47 +02:00

42 lines
1.3 KiB
TypeScript

import { NextResponse } from 'next/server';
import { z } from 'zod';
import { withAuth, withPermission } from '@/lib/api/helpers';
import { parseBody } from '@/lib/api/route-helpers';
import { errorResponse } from '@/lib/errors';
import { listRelationships, createRelationship } from '@/lib/services/clients.service';
const createRelationshipSchema = z.object({
clientBId: z.string().min(1),
relationshipType: z.enum(['referred_by', 'broker_for', 'family_member', 'same_vessel', 'custom']),
description: z.string().optional(),
});
export const GET = withAuth(
withPermission('clients', 'view', async (req, ctx, params) => {
try {
const relationships = await listRelationships(params.id!, ctx.portId);
return NextResponse.json({ data: relationships });
} catch (error) {
return errorResponse(error);
}
}),
);
export const POST = withAuth(
withPermission('clients', 'edit', async (req, ctx, params) => {
try {
const body = await parseBody(req, createRelationshipSchema);
const rel = await createRelationship(params.id!, ctx.portId, body, {
userId: ctx.userId,
portId: ctx.portId,
ipAddress: ctx.ipAddress,
userAgent: ctx.userAgent,
});
return NextResponse.json({ data: rel }, { status: 201 });
} catch (error) {
return errorResponse(error);
}
}),
);