-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from ChangePlusPlusVandy/update-upcoming-event…
…s-API update events/upcoming API and add new API events/explore
- Loading branch information
Showing
3 changed files
with
67 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import dbConnect from '@/lib/dbConnect'; | ||
import VolunteerEvents from 'bookem-shared/src/models/VolunteerEvents'; | ||
import type { NextApiRequest, NextApiResponse } from 'next'; | ||
|
||
export default async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse | ||
) { | ||
// Get request method | ||
const { method } = req; | ||
|
||
switch (method) { | ||
/** | ||
* @route GET /api/events/explore | ||
* @desc Get all future events | ||
* @res QueriedVolunteerEventData[] | ||
*/ | ||
case 'GET': | ||
try { | ||
await dbConnect(); | ||
|
||
// Select all events where startDate > today order by progamDate ascending | ||
const events = await VolunteerEvents.find({ | ||
startDate: { $gt: new Date() }, | ||
}).sort({ startDate: 1 }); | ||
|
||
return res.status(200).json(events); | ||
} catch (error) { | ||
console.error(error); | ||
res.status(500).json({ message: error }); | ||
} | ||
break; | ||
|
||
// case 'POST': | ||
// case 'PUT': | ||
// case 'DELETE': | ||
default: | ||
// res.setHeader('Allow', ['GET', 'PUT', 'DELETE', 'POST']); | ||
res.status(405).end(`Method ${method} Not Allowed`); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters