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

Auto Event importing from Meetup Sources through single server endpoint. #455

Merged
merged 6 commits into from
Jan 30, 2025
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
153 changes: 130 additions & 23 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
"google-auth-library": "^9.14.2",
"googleapis": "^144.0.0",
"happy-dom": "^15.7.4",
"ical.js": "^2.1.0",
"node-fetch": "^3.3.2",
"nuxt": "^3.13.2",
"swiper": "^11.1.4",
"tailwind-merge": "^2.5.4",
Expand Down
66 changes: 1 addition & 65 deletions server/api/events.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { google } from 'googleapis'
import { JWT } from 'google-auth-library'
import { getEvents } from '../utils/calendar'

/*
Reference for folks who maybe curious.
Expand All @@ -11,69 +10,6 @@ Reference for folks who maybe curious.
- Refer to here https://dev.to/pedrohase/create-google-calender-events-using-the-google-api-and-service-accounts-in-nodejs-22m8
*/

/**
* Retrieves events from Google Calendar.
* @async
* @param {Object} options - The options object.
* @param {string} options.googleCalendarId - The ID of the Google Calendar should be an email.
* @param {Object} options.serviceAccountCredentials - The service account credentials for google authentication.
* @param {Date} options.startDate - The start date from which to retrieve events.
* @param {number} options.limitEvents - The maximum number of events to retrieve.
* @returns {Promise<Array>} An array of events.
*/
const getEvents = async ({
googleCalendarId,
serviceAccountCredentials,
startDate,
limitEvents,
}) => {
if (!startDate) {
startDate = new Date().toISOString()
}
else {
startDate = new Date(startDate).toISOString()
}

if (!limitEvents) {
limitEvents = 10
}

// get the credentials from the service account
const client = new JWT({
email: serviceAccountCredentials.client_email,
key: serviceAccountCredentials.private_key,
scopes: [ // set the right scope
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.events',
],
})

// get the calendar api using google
const calendar = google.calendar({ version: 'v3' })
// get the events from the calendar
const resposnse = await calendar.events.list({
auth: client,
calendarId: googleCalendarId,
timeMin: startDate,
maxResults: limitEvents,
singleEvents: true,
orderBy: 'startTime',
})

// return the events.
return resposnse.data.items
}
/**
* API endpoint for fetching events for DES.
* @param {Object} event - The event object.
* @param {string} startDate - Start date of the events you want to fetch (query param).
* @param {number} limitEvents - Limit the number of events to fetch (query param)
* @example
* // Example usage:
* // GET /api/events?startDate=2024-05-01&limitEvents=25
* // GET /api/events
*/

export default defineEventHandler(async (event) => {
// get the query params

Expand Down
Loading