11// This file defines the API route for POST /api/reports
22// It lets logged-in users submit a report for a specific file.
33
4- import { NextResponse } from " next/server" ; // Used to send HTTP responses (JSON, status codes)
5- import { z } from " zod" ; // Zod validates and parses input data
4+ import { NextResponse } from ' next/server' ; // Used to send HTTP responses (JSON, status codes)
5+ import { z } from ' zod' ; // Zod validates and parses input data
66
77// Import database connection and the "report" table schema
8- import { db } from " @src/server/db" ;
9- import { report } from " @src/server/db/schema/reports" ;
8+ import { db } from ' @src/server/db' ;
9+ import { report } from ' @src/server/db/schema/reports' ;
1010
1111// Import session helper to check if a user is logged in
12- import { getServerAuthSession } from " @src/server/auth" ;
12+ import { getServerAuthSession } from ' @src/server/auth' ;
1313
1414// This ensures the API only accepts the correct fields
1515const CreateReportSchema = z . object ( {
16- fileId : z . string ( ) . min ( 1 ) ,
16+ fileId : z . string ( ) . min ( 1 ) ,
1717 category : z
18- . enum ( [ " inappropriate" , " copyright" , " spam" , " other" ] )
19- . default ( " other" ) ,
18+ . enum ( [ ' inappropriate' , ' copyright' , ' spam' , ' other' ] )
19+ . default ( ' other' ) ,
2020 details : z . string ( ) . min ( 1 ) ,
2121} ) ;
2222
@@ -26,7 +26,7 @@ export async function POST(req: Request) {
2626
2727 // If there’s no session or no user ID, reject the request
2828 if ( ! session ?. user ?. id ) {
29- return NextResponse . json ( { error : " Unauthorized" } , { status : 401 } ) ;
29+ return NextResponse . json ( { error : ' Unauthorized' } , { status : 401 } ) ;
3030 }
3131
3232 // Try to parse and validate the incoming request body
@@ -35,8 +35,8 @@ export async function POST(req: Request) {
3535 body = CreateReportSchema . parse ( await req . json ( ) ) ;
3636 } catch ( e ) {
3737 return NextResponse . json (
38- { error : " Invalid body" , details : ( e as Error ) . message } ,
39- { status : 400 }
38+ { error : ' Invalid body' , details : ( e as Error ) . message } ,
39+ { status : 400 } ,
4040 ) ;
4141 }
4242
0 commit comments