| 1 | import { z } from '@chatapp/common'; |
| 2 | |
| 3 | export const createUserSchema = z.object({ |
| 4 | email: z.string().email(), |
| 5 | displayName: z.string().min(3).max(255), |
| 6 | }); |
| 7 | |
| 8 | export const userIdParamsSchema = z.object({ |
| 9 | id: z.string().uuid(), |
| 10 | }); |
| 11 | |
| 12 | const excludeSchema = z.union([ |
| 13 | z.array(z.string().uuid()), |
| 14 | z |
| 15 | .string() |
| 16 | .uuid() |
| 17 | .transform((value) => [value]) |
| 18 | .optional() |
| 19 | .transform((value) => value ?? []), |
| 20 | ]); |
| 21 | |
| 22 | export const searchUsersQuerySchema = z.object({ |
| 23 | query: z.string().trim().min(3).max(255), |
| 24 | limit: z |
| 25 | .union([z.string(), z.number()]) |
| 26 | .transform((value) => Number()) |
| 27 | .refine((value) => Number.isInteger(value) && value > 0 && value <= 25, { |
| 28 | message: 'Limit must be between 1 and 25', |
| 29 | }) |
| 30 | .optional(), |
| 31 | exclude: excludeSchema, |
| 32 | }); |
| 33 | |
| 34 | export type SearchUsersQuery = z.infer<typeof searchUsersQuerySchema>; |