firt attempt for an ics calendar

This commit is contained in:
Thomas Ruoff
2020-09-16 00:31:42 +02:00
committed by Thomas Ruoff
parent 2b0cbe565f
commit 56c8263e90
5 changed files with 121 additions and 0 deletions

20
helpers/ical.ts Normal file
View File

@@ -0,0 +1,20 @@
import { createEvents } from 'ics'
import { BookingDocument } from '../db/booking'
export function generateBookedCalendar(bookings: BookingDocument[]) {
const events = bookings.map((booking) => ({
title: `Buchung ${booking.booker.name}`,
description: `UUID: ${booking.uuid}
Link: http://${process.env.VERCEL_URL}/booking/${booking.uuid}`,
start: booking.days[0].split('-'),
end: booking.days[booking.days.length - 1].split('-'),
}))
// ts-ignore
const { error, value } = createEvents(events)
if (error) {
throw new Error(error)
}
return value
}