35 lines
1020 B
TypeScript
35 lines
1020 B
TypeScript
import { z } from 'zod'
|
|
import { createSelectSchema, createInsertSchema } from 'drizzle-zod'
|
|
import { table as $t } from '~/db'
|
|
import { roleEnum } from '~/db/schema/users'
|
|
|
|
export const selectUserSchema = createSelectSchema($t.users)
|
|
export const $s = selectUserSchema.shape
|
|
export const $i = createInsertSchema($t.users).shape
|
|
|
|
export const roleSchema = createSelectSchema(roleEnum)
|
|
|
|
export const createUserBody = z.object({
|
|
name: $i.name.min(3),
|
|
email: $i.email,
|
|
phone: z.string().optional(),
|
|
password: z.string().min(8),
|
|
role: roleSchema.optional(), // will validate in service
|
|
partnerId: z.string().optional(),
|
|
})
|
|
export type CreateUserSchema = z.infer<typeof createUserBody>
|
|
|
|
export const createUserResponse = selectUserSchema.pick({
|
|
id: true,
|
|
name: true,
|
|
email: true,
|
|
phone: true,
|
|
role: true,
|
|
status: true,
|
|
createdAt: true,
|
|
})
|
|
export const listUserResponse = z.array(createUserResponse)
|
|
|
|
export type User = typeof $t.users.$inferSelect
|
|
export type NewUser = typeof $t.users.$inferInsert
|