mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
endDate is exclusive for allday events
This commit is contained in:
@@ -80,3 +80,7 @@ export function nowInTz(timezone = 'Europe/Berlin'): Date {
|
||||
const now = new Date()
|
||||
return utcToZonedTime(now, timezone)
|
||||
}
|
||||
|
||||
export function getNextDay(date: Date) {
|
||||
return addDays(date, 1)
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user