Files
pwa/backend/src/modules/users/users.schemas.ts
T

31 lines
888 B
TypeScript
Raw Normal View History

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 = 12;
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}`);
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>;