File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import { ok } from "../utils/response.js" ;
22import { createUser , listUsers } from "../services/userService.js" ;
3+ import { createUserSchema } from "../validators/user.js" ;
34
45export async function getUsers ( req , res ) {
56 return ok ( res , await listUsers ( ) ) ;
67}
78
89export async function postUser ( req , res ) {
9- return ok ( res , await createUser ( req . body ) , 201 ) ;
10+ const payload = createUserSchema . parse ( req . body ) ;
11+ return ok ( res , await createUser ( payload ) , 201 ) ;
1012}
Original file line number Diff line number Diff line change 1+ import { z } from "zod" ;
2+
3+ export const createUserSchema = z . object ( {
4+ email : z . string ( ) . email ( ) ,
5+ name : z . string ( ) . min ( 1 ) . max ( 100 ) ,
6+ role : z . enum ( [ "client" , "freelancer" , "admin" ] ) . default ( "client" )
7+ } ) ;
8+
9+ export const updateUserSchema = createUserSchema . partial ( ) ;
You can’t perform that action at this time.
0 commit comments