Skip to content

Commit

Permalink
update schema
Browse files Browse the repository at this point in the history
  • Loading branch information
likui628 committed Oct 2, 2024
1 parent 12eb673 commit 504a6e4
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
10 changes: 5 additions & 5 deletions src/validations/auth.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { z } from 'zod'
import { password } from './common'
import { name, password, email } from './common'

export const userRegisterSchema = z.object({
body: z.object({
email: z.string().email(),
email,
password,
name: z.string(),
name,
}),
})

export const userLoginSchema = z.object({
body: z.object({
email: z.string().email(),
password: z.string().min(6),
email,
password,
}),
})
4 changes: 4 additions & 0 deletions src/validations/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@ export const password = z
/^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[@$!%*?&])[A-Za-z\d@$!%*?&]{8,}$/,
'Password must contain at least one uppercase letter, one lowercase letter, one number, and one special character',
)

export const name = z.string().min(1, 'Name cannot be empty').max(100)

export const email = z.string().email().max(255)
6 changes: 3 additions & 3 deletions src/validations/user.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod'
import { Role } from '@prisma/client'
import { paginationSchema, password } from './common'
import { paginationSchema, password, name, email } from './common'

export const getUsersSchema = z.object({
query: z
Expand All @@ -13,9 +13,9 @@ export const getUsersSchema = z.object({

export const createUserSchema = z.object({
body: z.object({
email: z.string().email().max(255),
email,
password,
name: z.string().min(1, 'Name cannot be empty').max(100),
name,
role: z.enum([Role.ADMIN, Role.USER]),
}),
})

0 comments on commit 504a6e4

Please sign in to comment.