Adds Office 365 / Outlook.com Calendar Integration
* Added MS_GRAPH_CLIENT_* credentials to .env.example. * Refactored the google integration into an abstraction layer for creating events and getting the user schedule from either Google or Office 365. * FIX: when re-authorizing the Google Integration the refresh_token would no longer be set and the google integration would stop working. * Updated Office 365 integration image
This commit is contained in:
1 parent
ce398bd77c
commit
8010abf15a
12 files changed
+365
-110
No files matched your search
@@ -1,8 +1,6 @@
|
||||
import type { NextApiRequest, NextApiResponse } from 'next';
|
||||
import prisma from '../../../lib/prisma';
|
||||
const {google} = require('googleapis');
|
||||
|
||||
const credentials = process.env.GOOGLE_API_CREDENTIALS;
|
||||
import { getBusyTimes } from '../../../lib/calendarClient';
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
const { user } = req.query
|
||||
@@ -17,32 +15,6 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||
}
|
||||
});
|
||||
|
||||
let availability = [];
|
||||
|
||||
authorise(getAvailability)
|
||||
|
||||
// Set up Google API credentials
|
||||
function authorise(callback) {
|
||||
const {client_secret, client_id, redirect_uris} = JSON.parse(credentials).web;
|
||||
const oAuth2Client = new google.auth.OAuth2(client_id, client_secret, redirect_uris[0]);
|
||||
oAuth2Client.setCredentials(currentUser.credentials[0].key);
|
||||
callback(oAuth2Client)
|
||||
}
|
||||
|
||||
function getAvailability(auth) {
|
||||
const calendar = google.calendar({version: 'v3', auth});
|
||||
calendar.freebusy.query({
|
||||
requestBody: {
|
||||
timeMin: req.query.dateFrom,
|
||||
timeMax: req.query.dateTo,
|
||||
items: [{
|
||||
"id": "primary"
|
||||
}]
|
||||
}
|
||||
}, (err, apires) => {
|
||||
if (err) return console.log('The API returned an error: ' + err);
|
||||
availability = apires.data.calendars;
|
||||
res.status(200).json(availability);
|
||||
});
|
||||
}
|
||||
const availability = await getBusyTimes(currentUser.credentials, req.query.dateFrom, req.query.dateTo);
|
||||
res.status(200).json(availability);
|
||||
}
|
||||
Reference in new issue
Block a user