gitscope
← marzneshin / v0.6.2 / dashboard/src/modules/users/domain/schema.ts
https://dev.kronoz.win/r/marzneshin.git
dashboard/src/modules/users/domain/schema.ts · TypeScript
Blame Raw
 1import { z } from 'zod';
 2import { DATA_LIMIT_METRIC } from '@marzneshin/modules/users';
 3
 4export const UserSchema = z.object({
 5    username: z.string().min(1, { message: 'Username is required' }),
 6    note: z.string().nullable(),
 7    data_limit: z
 8        .union([z.string().transform((str) => (Number(str))), z.number()])
 9        .refine(val => val >= 0, { message: 'The minimum number is 0' })
10        .transform((val) => (Math.round(val)) * DATA_LIMIT_METRIC)
11        .nullable()
12        .optional(),
13    data_limit_reset_strategy: z
14        .enum(["no_reset", "day", "week", "month", "year"])
15        .or(z.number())
16        .or(z.string())
17        .nullable().optional(),
18    expire_strategy: z.enum(["never", "fixed_date", "start_on_first_use"]),
19    usage_duration: z.number().nullable().optional(),
20    activation_deadline: z
21        .string()
22        .or(z.date())
23        .nullable()
24        .optional(),
25    expire_date: z
26        .string()
27        .or(z.date())
28        .nullable()
29        .optional(),
30    service_ids: z
31        .array(z.number().or(z.string()))
32        .nonempty({ message: 'At least one service is required' })
33        .transform((v) => v.map(Number)),
34});
35
36export type UserMutationType = z.infer<typeof UserSchema>;