@@ -15,10 +15,10 @@ const uploadFormSchema = z.object({
1515 prefix : z . string ( ) . min ( 1 , { message : 'Prefix is missing' } ) ,
1616 courseNumber : z . string ( ) . min ( 1 , { message : 'Course number is missing' } ) ,
1717 sectionCode : z . string ( ) . min ( 1 , { message : 'Section code is missing' } ) ,
18- professor : z . string ( ) . min ( 1 , { message : 'Professor is missing' } ) ,
18+ professor : z . string ( ) . min ( 1 , { message : 'Professor is missing' } ) ,
1919 term : z . enum ( [ 'Spring' , 'Summer' , 'Fall' ] ) ,
20- year : z . coerce . number ( { message : 'Year is missing' } ) ,
21- } )
20+ year : z . coerce . number ( { message : 'Year is missing' } ) ,
21+ } ) ;
2222
2323// Upload file to database w/ file metadata (Local)
2424export async function POST ( req : Request ) {
@@ -42,17 +42,11 @@ export async function POST(req: Request) {
4242 const newFile = data . file as File ;
4343
4444 if ( ! ( newFile instanceof File ) ) {
45- return NextResponse . json (
46- { error : 'Invalid file upload' } ,
47- { status : 400 } ,
48- ) ;
45+ return NextResponse . json ( { error : 'Invalid file upload' } , { status : 400 } ) ;
4946 }
50-
47+
5148 if ( newFile . size === 0 ) {
52- return NextResponse . json (
53- { error : 'File is empty' } ,
54- { status : 400 } ,
55- ) ;
49+ return NextResponse . json ( { error : 'File is empty' } , { status : 400 } ) ;
5650 }
5751
5852 if ( ! allowedTypes . includes ( newFile . type ) ) {
@@ -76,10 +70,7 @@ export async function POST(req: Request) {
7670 } ) ;
7771
7872 if ( ! sectionData ) {
79- return NextResponse . json (
80- { error : 'Section not found' } ,
81- { status : 404 } ,
82- ) ;
73+ return NextResponse . json ( { error : 'Section not found' } , { status : 404 } ) ;
8374 }
8475
8576 try {
@@ -96,10 +87,10 @@ export async function POST(req: Request) {
9687 const fileMetadata = {
9788 authorId : session . user . id ,
9889 sectionId : sectionData . id ,
99- fileTitle : newFile . name , // required by schema
100- fileName : newFile . name , // required by schema
90+ fileTitle : newFile . name , // required by schema
91+ fileName : newFile . name , // required by schema
10192 } ;
102-
93+
10394 const result = await db . insert ( file ) . values ( fileMetadata ) . returning ( ) ;
10495
10596 return NextResponse . json (
@@ -108,9 +99,6 @@ export async function POST(req: Request) {
10899 ) ;
109100 } catch ( err ) {
110101 console . error ( 'File upload error:' , err ) ;
111- return NextResponse . json (
112- { error : 'File upload failed' } ,
113- { status : 500 } ,
114- ) ;
102+ return NextResponse . json ( { error : 'File upload failed' } , { status : 500 } ) ;
115103 }
116104}
0 commit comments