gemma: generate packages/shared/src/schemas.ts
This commit is contained in:
parent
940e492359
commit
a28fe0da82
69
packages/shared/src/schemas.ts
Normal file
69
packages/shared/src/schemas.ts
Normal file
@ -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<typeof UserInsertSchema>
|
||||
export type UserSelect = z.infer<typeof UserSelectSchema>
|
||||
export type UserRole = z.infer<typeof UserRoleSchema>
|
||||
|
||||
export type CustomerInsert = z.infer<typeof CustomerInsertSchema>
|
||||
export type CustomerSelect = z.infer<typeof CustomerSelectSchema>
|
||||
|
||||
export type ProjectInsert = z.infer<typeof ProjectInsertSchema>
|
||||
export type ProjectSelect = z.infer<typeof ProjectSelectSchema>
|
||||
|
||||
export type TimeEntryInsert = z.infer<typeof TimeEntryInsertSchema>
|
||||
export type TimeEntrySelect = z.infer<typeof TimeEntrySelectSchema>
|
||||
|
||||
export type LoginRequest = z.infer<typeof LoginRequestSchema>
|
||||
Loading…
Reference in New Issue
Block a user