From a11d8ffb9d1afeb6310341a83cf7fee2b64315b4 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Sun, 3 Dec 2023 23:18:48 -0600 Subject: [PATCH 1/4] Return both current and future events --- pages/api/events/upcoming.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/pages/api/events/upcoming.ts b/pages/api/events/upcoming.ts index b392c6d..f7fcaf5 100644 --- a/pages/api/events/upcoming.ts +++ b/pages/api/events/upcoming.ts @@ -33,9 +33,21 @@ export default async function handler( } // Use the user's events array to filter the VolunteerEvents + // select * from events where id in user.events and (startDate > today or (startDate < today and endDate > today)) + const currentDate = new Date(); const events = await VolunteerEvents.find({ _id: { $in: user.events }, - startDate: { $gt: new Date() }, + $or: [ + { + startDate: { $gt: currentDate }, + }, + { + $and: [ + { startDate: { $lte: currentDate } }, + { endDate: { $gt: currentDate } }, + ], + }, + ], }).sort({ startDate: 1 }); return res.status(200).json(events); From ffe4d4cfbf920f5560e51fa8e4d7ca959f59ab3e Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Sun, 3 Dec 2023 23:19:01 -0600 Subject: [PATCH 2/4] Modify comments in log-hour endpoint --- pages/api/events/log-hour.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/api/events/log-hour.ts b/pages/api/events/log-hour.ts index 16bb466..152e04d 100644 --- a/pages/api/events/log-hour.ts +++ b/pages/api/events/log-hour.ts @@ -16,8 +16,8 @@ export default async function handler( switch (method) { /** - * @route GET /api/events/upcoming - * @desc Get all events in the future that the user is signed up for + * @route GET /api/events/log-hour + * @desc Get all events where start date is before today * @res QueriedVolunteerEventData[] */ case 'GET': From a0682c3424b35a30881937cd78329528f62bf2a4 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Sun, 3 Dec 2023 23:20:00 -0600 Subject: [PATCH 3/4] Rename files --- components/Home/UpcomingEvents.tsx | 2 +- pages/api/events/{upcoming.ts => upcoming-current.ts} | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) rename pages/api/events/{upcoming.ts => upcoming-current.ts} (93%) diff --git a/components/Home/UpcomingEvents.tsx b/components/Home/UpcomingEvents.tsx index 48fcafc..8cda453 100644 --- a/components/Home/UpcomingEvents.tsx +++ b/components/Home/UpcomingEvents.tsx @@ -28,7 +28,7 @@ const UpcomingEvents = () => { const [error, setError] = useState(); // Fetch upcoming events when rendered useEffect(() => { - fetchData('/api/events/upcoming') + fetchData('/api/events/upcoming-current') .then(data => setEvents(data)) .catch(err => setError(err)); }, []); diff --git a/pages/api/events/upcoming.ts b/pages/api/events/upcoming-current.ts similarity index 93% rename from pages/api/events/upcoming.ts rename to pages/api/events/upcoming-current.ts index f7fcaf5..b1a546c 100644 --- a/pages/api/events/upcoming.ts +++ b/pages/api/events/upcoming-current.ts @@ -16,8 +16,8 @@ export default async function handler( switch (method) { /** - * @route GET /api/events/upcoming - * @desc Get all events in the future that the user is signed up for + * @route GET /api/events/upcoming-current + * @desc Get all events in the future and in the present that the user is signed up for * @res QueriedVolunteerEventData[] */ case 'GET': From 318a73ae433539a3c68e58e4229315e46eeb8e35 Mon Sep 17 00:00:00 2001 From: Harry Huang Date: Sun, 3 Dec 2023 23:21:09 -0600 Subject: [PATCH 4/4] Modify frontend display --- components/Home/MainDashboard.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/Home/MainDashboard.tsx b/components/Home/MainDashboard.tsx index 8a36aa4..7125981 100644 --- a/components/Home/MainDashboard.tsx +++ b/components/Home/MainDashboard.tsx @@ -111,7 +111,7 @@ const MainDashboard = ({ userData }: { userData: QueriedUserData | null }) => {
-
Your upcoming events
+
Your current and upcoming events
{/* TODO: add a filter icon on the right */}