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:
36
src/lib/validators/company-memberships.ts
Normal file
36
src/lib/validators/company-memberships.ts
Normal 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>;
|
||||
Reference in New Issue
Block a user