1+ import { requireAuth } from '@/lib/auth/auth' ;
12import { userController } from '@/lib/controllers/user.controller' ;
23import { sargeApiError , sargeApiResponse } from '@/lib/responses' ;
34import { UserNotFoundError } from '@/lib/schemas/user.schema' ;
45import { type NextRequest } from 'next/server' ;
56
67export async function DELETE (
78 _request : NextRequest ,
8- { params } : { params : Promise < { userId : string } > }
9+ { params } : { params : Promise < { id : string } > }
910) {
1011 try {
11- const userId = ( await params ) . userId ;
12- const user = await userController . delete ( userId ) ;
12+ const session = await requireAuth ( ) ;
13+
14+ const id = ( await params ) . id ;
15+ const user = await userController . delete ( id ) ;
1316 return sargeApiResponse ( user , 200 ) ;
1417 } catch ( error ) {
1518 if ( error instanceof UserNotFoundError ) {
@@ -21,13 +24,10 @@ export async function DELETE(
2124 }
2225}
2326
24- export async function GET (
25- _request : NextRequest ,
26- { params } : { params : Promise < { userId : string } > }
27- ) {
27+ export async function GET ( _request : NextRequest , { params } : { params : Promise < { id : string } > } ) {
2828 try {
29- const userId = ( await params ) . userId ;
30- const user = await userController . get ( userId ) ;
29+ const id = ( await params ) . id ;
30+ const user = await userController . get ( id ) ;
3131 return sargeApiResponse ( user , 200 ) ;
3232 } catch ( error ) {
3333 if ( error instanceof UserNotFoundError ) {
@@ -39,14 +39,11 @@ export async function GET(
3939 }
4040}
4141
42- export async function PUT (
43- request : NextRequest ,
44- { params } : { params : Promise < { userId : string } > }
45- ) {
42+ export async function PUT ( request : NextRequest , { params } : { params : Promise < { id : string } > } ) {
4643 try {
47- const userId = ( await params ) . userId ;
44+ const id = ( await params ) . id ;
4845 const body = await request . json ( ) ;
49- const user = await userController . update ( userId , body ) ;
46+ const user = await userController . update ( id , body ) ;
5047 return sargeApiResponse ( user , 200 ) ;
5148 } catch ( error ) {
5249 if ( error instanceof UserNotFoundError ) {
0 commit comments