33 lines
990 B
TypeScript
33 lines
990 B
TypeScript
import { z } from 'zod';
|
|||
|
|
|
||
|
|
export const NAME_MAX_LENGTH = 100;
|
||
|
|
|
||
|
|
export const profileNameSchema = z
|
||
|
|
.string({ required_error: 'Name is required' })
|
||
|
|
.trim()
|
||
|
|
.min(1, 'Name cannot be empty')
|
||
|
|
.max(NAME_MAX_LENGTH, `Name must be at most ${NAME_MAX_LENGTH} characters`);
|
||
|
|
|
||
|
|
export const PROFILE_AGE_MIN = 18;
|
||
|
|
export const PROFILE_AGE_MAX = 100;
|
||
|
|
|
||
|
|
export const profileAgeSchema = z
|
||
|
|
.number({
|
||
|
|
required_error: 'Age is required',
|
||
|
|
invalid_type_error: 'Age must be an integer',
|
||
|
|
})
|
||
|
|
.int('Age must be an integer')
|
||
|
|
.min(PROFILE_AGE_MIN, `Age must be at least ${PROFILE_AGE_MIN}`)
|
||
|
|
.max(PROFILE_AGE_MAX, `Age must be at most ${PROFILE_AGE_MAX}`);
|
||
|
|
|
||
|
|
export const patchProfileSchema = z
|
||
|
|
.object({
|
||
|
|
name: profileNameSchema.optional(),
|
||
|
|
age: profileAgeSchema.optional(),
|
||
|
|
})
|
||
|
|
.refine((value) => value.name !== undefined || value.age !== undefined, {
|
||
|
|
message: 'At least one of name or age is required',
|
||
|
|
});
|
||
|
|
|
||
|
|
export type PatchProfileInput = z.infer<typeof patchProfileSchema>;
|