File tree Expand file tree Collapse file tree 3 files changed +205
-136
lines changed
api/volunteer/[_id]/entries Expand file tree Collapse file tree 3 files changed +205
-136
lines changed Original file line number Diff line number Diff line change 1+ # WARNING: DO NOT MODIFY OR PUSH THIS FILE TO GIT
2+ # Use this to structure your actual .env file
13MONGO_URI =
24GOOGLE_ID =
35GOOGLE_SECRET =
46NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY =
57CLERK_SECRET_KEY =
6- NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL =
8+ NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL =
Original file line number Diff line number Diff line change 1+ import { NextRequest , NextResponse } from "next/server" ;
2+ import connectDB from "@database/db" ;
3+ import VolunteerEntries from "@database/volunteerEntrySchema" ;
4+
5+ type IParams = {
6+ params : {
7+ _id : string ;
8+ } ;
9+ } ;
10+
11+ // GET all entries for a specific volunteer, optionally filtered by an event ID
12+ export async function GET ( req : NextRequest , { params } : IParams ) {
13+ await connectDB ( ) ;
14+ const volunteerId = params . _id ;
15+
16+ const url = new URL ( req . url ) ;
17+ const eventId = url . searchParams . get ( "eventId" ) ;
18+
19+ try {
20+ const query : { volunteerId : string ; eventId ?: string } = { volunteerId } ;
21+ if ( eventId ) {
22+ query [ "eventId" ] = eventId ;
23+ }
24+
25+ const entries = await VolunteerEntries . find ( query ) . lean ( ) ;
26+
27+ if ( entries . length > 0 ) {
28+ console . log ( "entries: " , entries ) ;
29+ return NextResponse . json ( entries ) ;
30+ } else {
31+ return NextResponse . json ( [ ] , { status : 200 } ) ;
32+ }
33+ } catch ( err ) {
34+ console . error ( "Error fetching entries:" , err ) ;
35+ return NextResponse . json (
36+ { message : "Error fetching entries" , error : err } ,
37+ { status : 500 }
38+ ) ;
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments