-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsignup-submit.js
57 lines (43 loc) · 1.36 KB
/
signup-submit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import { google } from 'googleapis';
export default async function handler(req, res) {
console.log(`submitted form`, req.body, __filename)
const calendarId =
'finos.org_fac8mo1rfc6ehscg0d80fi8jig@group.calendar.google.com';
const eventId = req.body.eventId;
// Replace with the path to your service account JSON file
const SERVICE_ACCOUNT_FILE = './calendar-service-account.json'
// Scopes required for the Google Calendar API
const SCOPES = [
'https://www.googleapis.com/auth/calendar'
];
// Create a JWT client using the service account key
const auth = new google.auth.GoogleAuth({
keyFile: SERVICE_ACCOUNT_FILE,
scopes: SCOPES,
clientOptions: {
subject: 'rob.moffat@finos.org', // Specify the user to impersonate
},
});
//const client = auth.getClient()
// Create a Calendar API client
const calendar = google.calendar({ version: 'v3', auth });
const event = (await calendar.events.get({
calendarId: calendarId,
eventId: eventId,
})).data
console.log(`event`, event)
const existingAttendees = event.attendees ?? []
const done = await calendar.events.patch({
calendarId: calendarId,
eventId: eventId,
resource: {
attendees: [
...existingAttendees,
{
email: req.body.email,
},
]
}
})
res.json(`ok bebob ${JSON.stringify("hello")}`)
}