mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
21 lines
582 B
TypeScript
21 lines
582 B
TypeScript
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
|
|
}
|