Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/app/api/volunteerSession/route.client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ export const addVolunteerSession = async (
export const updateVolunteerSession = async (userId: string) => {
return fetchApi("/api/volunteerSession", "PATCH", { userId });
};

export const getVolunteerSessions = async (userId: string) => {
const url = `/api/volunteerSession?userId=${userId}`;
return fetchApi(url, "GET");
};
53 changes: 53 additions & 0 deletions src/app/api/volunteerSession/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,59 @@ export const POST = async (request: NextRequest) => {
}
};

export const GET = async (request: NextRequest) => {
const { searchParams } = new URL(request.url);
const userId: string | undefined = searchParams.get("userId") || undefined;

if (!userId) {
return NextResponse.json(
{
code: "BAD_REQUEST",
message: "User ID is required.",
},
{
status: 400,
}
);
}

try {
const volunteerSessions = await prisma.volunteerSession.findMany({
where: {
userId: userId,
NOT: [{ checkOutTime: null }, { durationHours: null }],
},
});

if (!volunteerSessions) {
return NextResponse.json(
{
code: "NOT_FOUND",
message: "No volunteer sessions found",
},
{ status: 404 }
);
}

return NextResponse.json(
{
code: "SUCCESS",
data: volunteerSessions,
},
{ status: 200 }
);
} catch (error) {
console.error("Error:", error);
return NextResponse.json(
{
code: "ERROR",
message: error,
},
{ status: 404 }
);
}
};

export const PATCH = async (request: NextRequest) => {
try {
const { userId } = await request.json();
Expand Down
1 change: 1 addition & 0 deletions src/app/private/events/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ export default function EventsPage() {
<Calendar
selectedDate={selectedDate}
setSelectedDate={setSelectedDate}
previousDisabled
/>
</div>
<div className="flex-1 flex flex-col text-start gap-y-[32px]">
Expand Down
Loading