Skip to content

Commit 302e435

Browse files
authored
Merge pull request #100 from hack4impact-calpoly/97-multiple-signups
(Resolves #97) Prevent multiple signups
2 parents db021e6 + da01c82 commit 302e435

File tree

3 files changed

+205
-136
lines changed

3 files changed

+205
-136
lines changed

.env.template

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
# WARNING: DO NOT MODIFY OR PUSH THIS FILE TO GIT
2+
# Use this to structure your actual .env file
13
MONGO_URI=
24
GOOGLE_ID=
35
GOOGLE_SECRET=
46
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
57
CLERK_SECRET_KEY=
6-
NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL=
8+
NEXT_PUBLIC_CLERK_SIGN_UP_FORCE_REDIRECT_URL=
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
}

0 commit comments

Comments
 (0)