Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show current events #73

Merged
merged 4 commits into from
Dec 4, 2023
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
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
Loading