11import { z } from 'zod' ;
22import { hashPassword } from '@/lib/password' ;
33import { parseRequest } from '@/lib/request' ;
4- import { badRequest , json , ok , unauthorized } from '@/lib/response' ;
4+ import { badRequest , json , notFound , ok , unauthorized } from '@/lib/response' ;
55import { userRoleParam } from '@/lib/schema' ;
66import { canDeleteUser , canUpdateUser , canViewUser } from '@/permissions' ;
77import { deleteUser , getUser , getUserByUsername , updateUser } from '@/queries/prisma' ;
@@ -27,7 +27,7 @@ export async function GET(request: Request, { params }: { params: Promise<{ user
2727export async function POST ( request : Request , { params } : { params : Promise < { userId : string } > } ) {
2828 const schema = z . object ( {
2929 username : z . string ( ) . max ( 255 ) . optional ( ) ,
30- password : z . string ( ) . max ( 255 ) . optional ( ) ,
30+ password : z . string ( ) . min ( 8 ) . max ( 255 ) . optional ( ) ,
3131 role : userRoleParam . optional ( ) ,
3232 } ) ;
3333
@@ -47,6 +47,10 @@ export async function POST(request: Request, { params }: { params: Promise<{ use
4747
4848 const user = await getUser ( userId ) ;
4949
50+ if ( ! user ) {
51+ return notFound ( ) ;
52+ }
53+
5054 const data : any = { } ;
5155
5256 if ( password ) {
0 commit comments