File tree Expand file tree Collapse file tree 8 files changed +27
-24
lines changed Expand file tree Collapse file tree 8 files changed +27
-24
lines changed Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ import { connectToDatabase } from "@/lib/mongoose";
3
3
import Paper from "@/db/papers" ;
4
4
5
5
export const dynamic = "force-dynamic" ;
6
-
7
6
export async function GET ( req : Request ) {
8
7
try {
9
8
await connectToDatabase ( ) ;
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ export async function GET(req: NextRequest) {
13
13
const escapeRegExp = ( text : string ) => {
14
14
return text . replace ( / [ . * + ? ^ $ { } ( ) | [ \] \\ ] / g, "\\$&" ) ;
15
15
} ;
16
- const escapedSubject = escapeRegExp ( subject ! ) ;
16
+ const escapedSubject = escapeRegExp ( subject ?? "" ) ;
17
17
18
18
if ( ! subject ) {
19
19
return NextResponse . json (
@@ -28,7 +28,14 @@ export async function GET(req: NextRequest) {
28
28
29
29
if ( papers . length === 0 ) {
30
30
return NextResponse . json (
31
- { message : "No papers found for the specified subject" } ,
31
+ {
32
+ papers,
33
+ uniqueYears : [ ] ,
34
+ uniqueSlots : [ ] ,
35
+ uniqueExams : [ ] ,
36
+ uniqueCampuses : [ ] ,
37
+ uniqueSemesters : [ ] ,
38
+ } ,
32
39
{ status : 200 } ,
33
40
) ;
34
41
}
Original file line number Diff line number Diff line change @@ -4,18 +4,21 @@ import Paper from "@/db/papers";
4
4
5
5
export const dynamic = "force-dynamic" ;
6
6
7
+ interface TransformedPaper {
8
+ subject : string ;
9
+ slots : string [ ] ;
10
+ }
11
+
7
12
export async function POST ( req : Request ) {
8
13
try {
9
14
await connectToDatabase ( ) ;
10
- const body = await req . json ( ) ;
11
-
12
- const subjects : string [ ] = body ;
15
+ const subjects : string [ ] = await req . json ( ) as string [ ] ;
13
16
14
17
const usersPapers = await Paper . find ( {
15
18
subject : { $in : subjects } ,
16
19
} ) ;
17
20
18
- const transformedPapers = usersPapers . reduce ( ( acc , paper ) => {
21
+ const transformedPapers = usersPapers . reduce < TransformedPaper [ ] > ( ( acc , paper ) => {
19
22
const existing = acc . find ( ( item ) => item . subject === paper . subject ) ;
20
23
21
24
if ( existing ) {
@@ -27,15 +30,7 @@ export async function POST(req: Request) {
27
30
return acc ;
28
31
} , [ ] ) ;
29
32
30
- // check duplicates
31
- const seenSubjects = new Set ( ) ;
32
- const uniquePapers = transformedPapers . filter ( ( paper ) => {
33
- if ( seenSubjects . has ( paper . subject ) ) return false ;
34
- seenSubjects . add ( paper . subject ) ;
35
- return true ;
36
- } ) ;
37
-
38
- return NextResponse . json ( uniquePapers , {
33
+ return NextResponse . json ( transformedPapers , {
39
34
status : 200 ,
40
35
} ) ;
41
36
} catch ( error ) {
Original file line number Diff line number Diff line change @@ -81,7 +81,7 @@ const CatalogueContent = () => {
81
81
const papersData = data . papers ;
82
82
setFilterOptions ( data ) ;
83
83
setPapers ( papersData ) ;
84
- // Apply filters from URL params
84
+ // Apply filters from URL paramsfilterOptions?
85
85
const filtered = papersData . filter ( ( paper ) => {
86
86
const examCondition = selectedExams . length
87
87
? selectedExams . includes ( paper . exam )
Original file line number Diff line number Diff line change @@ -60,9 +60,9 @@ function PapersCarousel({
60
60
setIsLoading ( true ) ;
61
61
if ( carouselType === "users" ) {
62
62
const storedSubjects = JSON . parse (
63
- localStorage . getItem ( "userSubjects" ) ,
64
- ) ;
65
- const response = await axios . post ( "/api/user-papers" , storedSubjects ) ;
63
+ localStorage . getItem ( "userSubjects" ) ?? "[]"
64
+ ) as string [ ] ;
65
+ const response = await axios . post < IUpcomingPaper [ ] > ( "/api/user-papers" , storedSubjects ) ;
66
66
setDisplayPapers ( response . data ) ;
67
67
} else {
68
68
const response = await axios . get < IUpcomingPaper [ ] > (
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ function SearchBarChild({
15
15
filtersNotPulled ?: ( ) => void ;
16
16
} ) {
17
17
const router = useRouter ( ) ;
18
+ const [ count , setCount ] = useState ( 0 ) ;
18
19
const [ searchText , setSearchText ] = useState ( "" ) ;
19
20
const [ suggestions , setSuggestions ] = useState < string [ ] > ( [ ] ) ;
20
21
const suggestionsRef = useRef < HTMLUListElement | null > ( null ) ;
Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ export async function fetchSubjects() {
9
9
const response = await axios . get < ICourses [ ] > (
10
10
`${ process . env . SERVER_URL } /api/course-list` ,
11
11
) ;
12
+ console . log ( "Fetched subjects:" , response . data ) ;
12
13
return response . data . map ( ( course ) => course . name ) ;
13
14
} catch ( err ) {
14
15
console . error ( "Error fetching subjects:" , err ) ;
Original file line number Diff line number Diff line change @@ -57,19 +57,19 @@ function SideBar({
57
57
const exams = filterOptions ?. uniqueExams . map ( ( exam ) => ( {
58
58
label : exam ,
59
59
value : exam ,
60
- } ) ) ;
60
+ } ) ) ?? [ ] ;
61
61
const slots = filterOptions ?. uniqueSlots . map ( ( slot ) => ( {
62
62
label : slot ,
63
63
value : slot ,
64
- } ) ) ;
64
+ } ) ) ?? [ ] ;
65
65
const years = filterOptions ?. uniqueYears . map ( ( year ) => ( {
66
66
label : year ,
67
67
value : year ,
68
- } ) ) ;
68
+ } ) ) ?? [ ] ;
69
69
const semesters = filterOptions ?. uniqueSemesters . map ( ( semester ) => ( {
70
70
label : semester ,
71
71
value : semester ,
72
- } ) ) ;
72
+ } ) ) ?? [ ] ;
73
73
// const campuses = filterOptions?.uniqueCampuses.map((campus) => ({
74
74
// label: campus,
75
75
// value: campus,
You can’t perform that action at this time.
0 commit comments