gitscope
← marzneshin / nightly / 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()
18        .optional(),
19    expire_strategy: z.enum(["never", "fixed_date", "start_on_first_use"]),
20    usage_duration: z.number().max(9999 * 365 * 24 * 60 * 60, { message: "usage_duration must be less than 3649635" })
21        .nullable().optional(),
22    activation_deadline: z.string().or(z.date()).nullable().optional(),
23    expire_date: z.string().or(z.date()).nullable().optional(),
24    service_ids: z
25        .array(z.number().or(z.string()))
26        .nonempty({ message: "At least one service is required" })
27        .transform((v) => v.map(Number)),
28});
29
30export type UserMutationType = z.infer<typeof UserSchema>;