Phase 2: Create zod schemas in src/schemas/index.ts
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
const frequencyValues = [
|
||||
'Biennial',
|
||||
'Annually',
|
||||
'Biannually',
|
||||
'Quarterly',
|
||||
'EveryTwoMonths',
|
||||
'Monthly',
|
||||
'SemiMonthly',
|
||||
'Biweekly',
|
||||
'Weekly',
|
||||
] as const;
|
||||
|
||||
export const createBudgetSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required').max(200),
|
||||
});
|
||||
|
||||
export const createIncomeSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required').max(200),
|
||||
frequency: z.enum(frequencyValues),
|
||||
amount: z.coerce.number({ error: 'Amount is required' }).positive('Must be positive'),
|
||||
});
|
||||
|
||||
export const createOutgoSchema = z.object({
|
||||
name: z.string().min(1, 'Name is required').max(200),
|
||||
category: z.string().max(100).optional(),
|
||||
type: z.enum(['Need', 'Want', 'Save']),
|
||||
frequency: z.enum(frequencyValues),
|
||||
amount: z.coerce.number().positive('Must be positive'),
|
||||
paymentSource: z.string().max(100).optional(),
|
||||
notes: z.string().max(1000).optional(),
|
||||
});
|
||||
|
||||
export const createShareSchema = z.object({
|
||||
email: z.string().email('Must be a valid email'),
|
||||
permission: z.enum(['View', 'Edit']),
|
||||
});
|
||||
|
||||
export const updateTaxRateSchema = z.object({
|
||||
effectiveTaxRate: z.coerce.number().min(0).max(0.99),
|
||||
});
|
||||
|
||||
export type CreateBudgetInput = z.infer<typeof createBudgetSchema>;
|
||||
export type CreateIncomeInput = z.infer<typeof createIncomeSchema>;
|
||||
export type CreateOutgoInput = z.infer<typeof createOutgoSchema>;
|
||||
export type CreateShareInput = z.infer<typeof createShareSchema>;
|
||||
export type UpdateTaxRateInput = z.infer<typeof updateTaxRateSchema>;
|
||||
Reference in New Issue
Block a user