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 */} 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/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': diff --git a/pages/api/events/upcoming.ts b/pages/api/events/upcoming-current.ts similarity index 73% rename from pages/api/events/upcoming.ts rename to pages/api/events/upcoming-current.ts index b392c6d..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': @@ -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);