Skip to content

Commit

Permalink
Merge pull request #73 from ChangePlusPlusVandy/show-current-events
Browse files Browse the repository at this point in the history
Show current events
  • Loading branch information
JiashuHarryHuang authored Dec 4, 2023
2 parents 084e0ce + 318a73a commit cdada5a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
2 changes: 1 addition & 1 deletion components/Home/MainDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ const MainDashboard = ({ userData }: { userData: QueriedUserData | null }) => {
</div>

<div>
<Header>Your upcoming events</Header>
<Header>Your current and upcoming events</Header>
{/* TODO: add a filter icon on the right */}

<UpcomingEvents />
Expand Down
2 changes: 1 addition & 1 deletion components/Home/UpcomingEvents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const UpcomingEvents = () => {
const [error, setError] = useState<Error>();
// Fetch upcoming events when rendered
useEffect(() => {
fetchData('/api/events/upcoming')
fetchData('/api/events/upcoming-current')
.then(data => setEvents(data))
.catch(err => setError(err));
}, []);
Expand Down
4 changes: 2 additions & 2 deletions pages/api/events/log-hour.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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);
Expand Down

1 comment on commit cdada5a

@vercel
Copy link

@vercel vercel bot commented on cdada5a Dec 4, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

bookem-user – ./

bookem-user-bookem-user.vercel.app
bookem-user.vercel.app
bookem-user-git-main-bookem-user.vercel.app

Please sign in to comment.