- Replace per-model admin forms with the shared generic AdminTable/AdminModal CRUD - Add ProclamationGroup model and admin + API v2 routes (replaces subscription levels) - Drop subscription levels and flatten proclamation categories - Update v2 serializers and seed data accordingly
83 lines
2.3 KiB
TypeScript
83 lines
2.3 KiB
TypeScript
import { z } from 'zod';
|
|
|
|
const email = z.string().email('Invalid email address');
|
|
const phone = z
|
|
.string()
|
|
.min(10, 'Phone number must be at least 10 digits')
|
|
.regex(/^[\d\-\+\(\) ]+$/, 'Invalid phone number format');
|
|
const name = z.string().min(1, 'Required').max(100, 'Too long');
|
|
|
|
export const UserRole = z.object({
|
|
name: z.string().min(1, 'Required')
|
|
});
|
|
|
|
export const User = z.object({
|
|
name: z.string().min(1, 'Required'),
|
|
email,
|
|
roleId: z.coerce.number().int().min(1)
|
|
});
|
|
|
|
export const Profile = z
|
|
.object({
|
|
userId: z.string().optional(),
|
|
email: z.string().email('Invalid email address').optional(),
|
|
firstName: name,
|
|
lastName: name,
|
|
phoneNumber: phone
|
|
})
|
|
.refine((p) => p.userId || p.email, {
|
|
message: 'Provide either a user or an email',
|
|
path: ['email']
|
|
});
|
|
|
|
export const Address = z.object({
|
|
profileId: z.string().min(1),
|
|
street: z.string().min(1, 'Street is required'),
|
|
city: z.string().min(1, 'City is required'),
|
|
state: z.string().min(1, 'State is required'),
|
|
postalCode: z.string().min(1, 'Postal code is required'),
|
|
country: z.string().min(1, 'Country is required'),
|
|
type: z.enum(['Mailing', 'Billing', 'Shipping']).default('Mailing'),
|
|
isDefaultMailing: z.coerce.boolean().default(false),
|
|
isDefaultBilling: z.coerce.boolean().default(false),
|
|
isDefaultShipping: z.coerce.boolean().default(false)
|
|
});
|
|
|
|
export const SolfeggioFrequency = z.object({
|
|
name: z.string().min(1, 'Required'),
|
|
value: z.coerce.number().int('Must be a whole number')
|
|
});
|
|
|
|
export const ProclamationGroup = z.object({
|
|
name: z.string().min(1, 'Required')
|
|
});
|
|
|
|
export const ProclamationCategory = z.object({
|
|
name: z.string().min(1, 'Required')
|
|
});
|
|
|
|
export const Proclamation = z.object({
|
|
name: z.string().min(1, 'Required'),
|
|
solfeggioFrequencyId: z.coerce.number().int(),
|
|
categoryId: z.coerce.number().int(),
|
|
groupId: z.coerce.number().int(),
|
|
content: z.string().optional().default('')
|
|
});
|
|
|
|
export const LicenseKey = z
|
|
.object({
|
|
active: z.coerce.boolean(),
|
|
userId: z.string().optional(),
|
|
email: z.string().email('Invalid email address').optional()
|
|
})
|
|
.refine((k) => k.userId || k.email, {
|
|
message: 'Provide either a user or an email',
|
|
path: ['email']
|
|
});
|
|
|
|
export const UserUpdate = z.object({
|
|
id: z.string().min(1),
|
|
name: z.string().min(1, 'Required').optional(),
|
|
email: z.string().email().optional()
|
|
});
|