mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 23:17:12 +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()
|
const now = new Date()
|
||||||
return utcToZonedTime(now, timezone)
|
return utcToZonedTime(now, timezone)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getNextDay(date: Date) {
|
||||||
|
return addDays(date, 1)
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { google } from 'googleapis'
|
import { google } from 'googleapis'
|
||||||
import { getBaseURL } from '../helpers/url'
|
import { getBaseURL } from '../helpers/url'
|
||||||
import { Booking } from '../db/booking'
|
import { Booking } from '../db/booking'
|
||||||
import { getDays } from '../helpers/date'
|
import { getDays, getNextDay, dateFormatBackend } from '../helpers/date'
|
||||||
import { log } from '../helpers/log'
|
import { log } from '../helpers/log'
|
||||||
|
|
||||||
const calendarId = process.env.GOOGLE_CALENDAR_ID
|
const calendarId = process.env.GOOGLE_CALENDAR_ID
|
||||||
@@ -66,18 +66,19 @@ function getDescription(booking: Booking): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function createCalendarEvent(booking: Booking): Promise<Booking> {
|
export async function createCalendarEvent(booking: Booking): Promise<Booking> {
|
||||||
const response = await calendar.events.insert(
|
const exclusiveEndDate = dateFormatBackend(
|
||||||
{
|
getNextDay(new Date(booking.endDate))
|
||||||
|
)
|
||||||
|
const data = {
|
||||||
calendarId,
|
calendarId,
|
||||||
requestBody: {
|
requestBody: {
|
||||||
summary: getSummary(booking),
|
summary: getSummary(booking),
|
||||||
description: getDescription(booking),
|
description: getDescription(booking),
|
||||||
start: { date: booking.startDate },
|
start: { date: booking.startDate },
|
||||||
end: { date: booking.endDate },
|
end: { date: exclusiveEndDate },
|
||||||
},
|
},
|
||||||
},
|
}
|
||||||
{}
|
const response = await calendar.events.insert(data, {})
|
||||||
)
|
|
||||||
|
|
||||||
booking.calendarEventId = response.data.id
|
booking.calendarEventId = response.data.id
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user