🚩 create basic flow for fetching user data

This commit is contained in:
Rafi Arrafif
2025-07-17 23:20:00 +07:00
parent 30806e23e0
commit 9bc1b592d0
5 changed files with 58 additions and 12 deletions

View File

@ -1,9 +1,6 @@
import z from "zod";
const includeEnum = z.enum(
["preference", "roles"],
"option: include value didn't match with enum types"
);
const includeOptions = ["preference", "roles"] as const;
export const getUserOptionsSchema = z.object({
verbosity: z
@ -12,9 +9,12 @@ export const getUserOptionsSchema = z.object({
"option: verbosity value didn't match with enum types"
)
.optional(),
include: z.preprocess((val) => {
if (Array.isArray(val)) return val;
if (typeof val === "string") return [val];
return [];
}, z.array(includeEnum).optional()),
include: z
.string()
.optional()
.transform((val) => val?.split(",") ?? [])
.refine(
(arr) => arr.every((val) => includeOptions.includes(val.trim() as any)),
"option: include value didn't match with enum types"
),
});