fix calendar auth

This commit is contained in:
Thomas Ruoff
2022-03-14 22:32:16 +01:00
parent 5c293eb973
commit 1fff2457f7

View File

@@ -2,7 +2,7 @@ import { google } from 'googleapis'
import { Booking } from '../db/booking' import { Booking } from '../db/booking'
const calendarId = process.env.GOOGLE_CALENDAR_ID const calendarId = process.env.GOOGLE_CALENDAR_ID
let credentials let credentials: object
try { try {
credentials = JSON.parse(process.env.GOOGLE_SERVICE_ACCOUNT_KEY_JSON); credentials = JSON.parse(process.env.GOOGLE_SERVICE_ACCOUNT_KEY_JSON);
@@ -45,9 +45,7 @@ function getSummary(booking: Partial<Booking>): string {
} }
export async function createCalendarEvent(booking: Booking): Promise<Booking> { export async function createCalendarEvent(booking: Booking): Promise<Booking> {
const authInstance = await auth.getClient();
const response = await calendar.events.insert({ const response = await calendar.events.insert({
auth: authInstance,
calendarId, calendarId,
requestBody: { requestBody: {
summary: getSummary(booking), summary: getSummary(booking),
@@ -64,7 +62,6 @@ export async function createCalendarEvent(booking: Booking): Promise<Booking> {
export async function deleteCalendarEvent(booking: Booking) { export async function deleteCalendarEvent(booking: Booking) {
await calendar.events.delete({ await calendar.events.delete({
auth,
calendarId, calendarId,
eventId: booking.calendarEventId, eventId: booking.calendarEventId,
}) })
@@ -74,7 +71,6 @@ export async function deleteCalendarEvent(booking: Booking) {
//export async function patchCalendarEvent(booking: { calendarEventId: string } & Partial<Booking> ) : Promise<Booking> { //export async function patchCalendarEvent(booking: { calendarEventId: string } & Partial<Booking> ) : Promise<Booking> {
// const response = await calendar.events.patch({ // const response = await calendar.events.patch({
// auth,
// calendarId, // calendarId,
// eventId: booking.calendarEventId, // eventId: booking.calendarEventId,
// }); // });