diff --git a/packages/shared/src/schemas.ts b/packages/shared/src/schemas.ts new file mode 100644 index 0000000..2912c42 --- /dev/null +++ b/packages/shared/src/schemas.ts @@ -0,0 +1,69 @@ +import { z } from "zod" + +export const UserRoleSchema = z.enum(["admin", "user"]) + +export const UserInsertSchema = UserRoleSchema.extend({ + email: z.string().email(), + name: z.string().min(1), + role: UserRoleSchema, + passwordHash: z.string().min(1) +}) + +export const UserSelectSchema = UserInsertSchema.extend({ + id: z.string().uuid(), + createdAt: z.date() +}).omit({ passwordHash: true }) + +export const CustomerInsertSchema = z.object({ + name: z.string().min(1), + active: z.boolean().default(true) +}) + +export const CustomerSelectSchema = CustomerInsertSchema.extend({ + id: z.string().uuid(), + createdAt: z.date() +}) + +export const ProjectInsertSchema = z.object({ + name: z.string().min(1), + customerId: z.string().uuid(), + active: z.boolean().default(true) +}) + +export const ProjectSelectSchema = ProjectInsertSchema.extend({ + id: z.string().uuid(), + createdAt: z.date() +}) + +export const TimeEntryInsertSchema = z.object({ + userId: z.string().uuid(), + projectId: z.string().uuid().optional(), + description: z.string().min(1), + startTime: z.date(), + endTime: z.date().optional() +}) + +export const TimeEntrySelectSchema = TimeEntryInsertSchema.extend({ + id: z.string().uuid(), + createdAt: z.date() +}) + +export const LoginRequestSchema = z.object({ + email: z.string().email(), + password: z.string().min(1) +}) + +export type UserInsert = z.infer +export type UserSelect = z.infer +export type UserRole = z.infer + +export type CustomerInsert = z.infer +export type CustomerSelect = z.infer + +export type ProjectInsert = z.infer +export type ProjectSelect = z.infer + +export type TimeEntryInsert = z.infer +export type TimeEntrySelect = z.infer + +export type LoginRequest = z.infer \ No newline at end of file