feat(schema): Refactored valibot definitions to use helper function for cleaner enum handling

This commit is contained in:
Nicolas HOARAU 2026-06-10 02:09:51 +04:00
parent f11c306ac6
commit 2808f82c29

View file

@ -2,29 +2,33 @@ import { createInsertSchema, createSelectSchema, createUpdateSchema } from "driz
import { pipe, picklist } from "valibot";
import { projects, tasks, PROJECT_STATUSES, TASK_STATUSES, PRIORITIES } from "./drizzle/index";
const createProjectStatusSchema = (schema: any) => pipe(schema, picklist([...PROJECT_STATUSES])) as any;
const createTaskStatusSchema = (schema: any) => pipe(schema, picklist([...TASK_STATUSES])) as any;
const createPrioritySchema = (schema: any) => pipe(schema, picklist([...PRIORITIES])) as any;
export const projectSelect = createSelectSchema(projects, {
status: (schema: any) => pipe(schema, picklist([...PROJECT_STATUSES])) as any,
status: createProjectStatusSchema,
});
export const taskSelect = createSelectSchema(tasks, {
status: (schema: any) => pipe(schema, picklist([...TASK_STATUSES])) as any,
priority: (schema: any) => pipe(schema, picklist([...PRIORITIES])) as any,
status: createTaskStatusSchema,
priority: createPrioritySchema,
});
export const projectInsert = createInsertSchema(projects, {
status: (schema: any) => pipe(schema, picklist([...PROJECT_STATUSES])) as any,
status: createProjectStatusSchema,
});
export const projectUpdate = createUpdateSchema(projects, {
status: (schema: any) => pipe(schema, picklist([...PROJECT_STATUSES])) as any,
status: createProjectStatusSchema,
});
export const taskInsert = createInsertSchema(tasks, {
status: (schema: any) => pipe(schema, picklist([...TASK_STATUSES])) as any,
priority: (schema: any) => pipe(schema, picklist([...PRIORITIES])) as any,
status: createTaskStatusSchema,
priority: createPrioritySchema,
});
export const taskUpdate = createUpdateSchema(tasks, {
status: (schema: any) => pipe(schema, picklist([...TASK_STATUSES])) as any,
priority: (schema: any) => pipe(schema, picklist([...PRIORITIES])) as any,
status: createTaskStatusSchema,
priority: createPrioritySchema,
});