endDate is exclusive for allday events

This commit is contained in:
Thomas Ruoff
2022-07-06 22:50:44 +02:00
parent 3a4a4ad0b0
commit d89f9a8825
2 changed files with 17 additions and 12 deletions

View File

@@ -1,7 +1,7 @@
import { google } from 'googleapis'
import { getBaseURL } from '../helpers/url'
import { Booking } from '../db/booking'
import { getDays } from '../helpers/date'
import { getDays, getNextDay, dateFormatBackend } from '../helpers/date'
import { log } from '../helpers/log'
const calendarId = process.env.GOOGLE_CALENDAR_ID
@@ -66,18 +66,19 @@ function getDescription(booking: Booking): string {
}
export async function createCalendarEvent(booking: Booking): Promise<Booking> {
const response = await calendar.events.insert(
{
calendarId,
requestBody: {
summary: getSummary(booking),
description: getDescription(booking),
start: { date: booking.startDate },
end: { date: booking.endDate },
},
},
{}
const exclusiveEndDate = dateFormatBackend(
getNextDay(new Date(booking.endDate))
)
const data = {
calendarId,
requestBody: {
summary: getSummary(booking),
description: getDescription(booking),
start: { date: booking.startDate },
end: { date: exclusiveEndDate },
},
}
const response = await calendar.events.insert(data, {})
booking.calendarEventId = response.data.id