feat(company-memberships): service + validators + tests

Adds company-membership service with six operations (add, update, end,
setPrimary, listByCompany, listByClient), the corresponding Zod
validators, three socket events, and a unit-test suite covering the
portId-scoping rules, the unique_cm_exact conflict path, and the atomic
setPrimary transaction.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Matt Ciaccio
2026-04-24 12:07:58 +02:00
parent 037f2544e8
commit 15a79e7990
5 changed files with 816 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
import { z } from 'zod';
export const ROLES = [
'director',
'officer',
'broker',
'representative',
'legal_counsel',
'employee',
'shareholder',
'other',
] as const;
export const addMembershipSchema = z.object({
clientId: z.string().min(1),
role: z.enum(ROLES),
roleDetail: z.string().optional(),
startDate: z.coerce.date(),
isPrimary: z.boolean().optional().default(false),
notes: z.string().optional(),
});
export const updateMembershipSchema = z.object({
role: z.enum(ROLES).optional(),
roleDetail: z.string().nullable().optional(),
notes: z.string().nullable().optional(),
isPrimary: z.boolean().optional(),
});
export const endMembershipSchema = z.object({
endDate: z.coerce.date(),
});
export type AddMembershipInput = z.infer<typeof addMembershipSchema>;
export type UpdateMembershipInput = z.infer<typeof updateMembershipSchema>;
export type EndMembershipInput = z.infer<typeof endMembershipSchema>;