@@ -39,7 +39,7 @@ export async function POST(req: Request) {
39
39
const formData = await req . formData ( ) ;
40
40
const files : File [ ] = formData . getAll ( "files" ) as File [ ] ;
41
41
const isPdf = formData . get ( "isPdf" ) === "true" ; // Convert string to boolean
42
-
42
+
43
43
const orderedFiles = Array . from ( files ) . sort ( ( a , b ) => {
44
44
return a . name . localeCompare ( b . name ) ;
45
45
} ) ;
@@ -61,53 +61,53 @@ export async function POST(req: Request) {
61
61
const slot = finalTags . slot ;
62
62
const exam = finalTags [ "exam-type" ] ;
63
63
const year = finalTags . year ;
64
- const campus = formData . get ( "campus" ) as string
64
+ const campus = formData . get ( "campus" ) as string ;
65
65
const semester = finalTags . semester ;
66
66
67
67
if ( ! courses . includes ( subject ) ) {
68
68
return NextResponse . json (
69
69
{ message : "The course subject is invalid." } ,
70
- { status : 400 }
70
+ { status : 400 } ,
71
71
) ;
72
72
}
73
-
73
+
74
74
if ( ! slots . includes ( slot ) ) {
75
75
return NextResponse . json (
76
76
{ message : "The slot is invalid." } ,
77
- { status : 400 }
77
+ { status : 400 } ,
78
78
) ;
79
79
}
80
-
80
+
81
81
if ( ! exam . includes ( exam ) ) {
82
82
return NextResponse . json (
83
83
{ message : "The exam type is invalid." } ,
84
- { status : 400 }
84
+ { status : 400 } ,
85
85
) ;
86
86
}
87
-
87
+
88
88
if ( ! years . includes ( year ) ) {
89
89
return NextResponse . json (
90
90
{ message : "The year is invalid." } ,
91
- { status : 400 }
91
+ { status : 400 } ,
92
92
) ;
93
93
}
94
-
94
+
95
95
if ( ! campuses . includes ( campus ) ) {
96
96
return NextResponse . json (
97
- { message :`The ${ campus } is invalid.` } ,
98
- { status : 400 }
97
+ { message : `The ${ campus } is invalid.` } ,
98
+ { status : 400 } ,
99
99
) ;
100
100
}
101
-
101
+
102
102
if ( ! semesters . includes ( semester ) ) {
103
103
return NextResponse . json (
104
104
{ message : "The semester is invalid." } ,
105
- { status : 400 }
105
+ { status : 400 } ,
106
106
) ;
107
107
}
108
-
108
+
109
109
// If all checks pass, continue with the rest of the logic
110
-
110
+
111
111
await connectToDatabase ( ) ;
112
112
let finalUrl : string | undefined = "" ;
113
113
let public_id_cloudinary : string | undefined = "" ;
@@ -163,10 +163,7 @@ export async function POST(req: Request) {
163
163
semester,
164
164
} ) ;
165
165
await paper . save ( ) ;
166
- return NextResponse . json (
167
- { status : "success" , } ,
168
- { status : 201 } ,
169
- ) ;
166
+ return NextResponse . json ( { status : "success" } , { status : 201 } ) ;
170
167
} catch ( error ) {
171
168
console . error ( error ) ;
172
169
return NextResponse . json (
@@ -290,11 +287,6 @@ async function setTagsFromCurrentLists(
290
287
}
291
288
function findMatch < T > ( arr : T [ ] , value : string | undefined ) : T | undefined {
292
289
if ( ! value ) return undefined ; // Handle undefined case
293
- const pattern = new RegExp (
294
- value
295
- . split ( "" )
296
- . map ( ( char ) => `(?=.*${ char } )` )
297
- . join ( "" ) ,
298
- "i"
299
- ) ; return arr . find ( ( item ) => pattern . test ( String ( item ) ) ) ;
300
- }
290
+ const pattern = new RegExp ( value , "i" ) ;
291
+ return arr . find ( ( item ) => pattern . test ( String ( item ) ) ) ;
292
+ }
0 commit comments