mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 06:27:11 +01:00
improve ical
This commit is contained in:
committed by
Thomas Ruoff
parent
c136b2d2e1
commit
826dd44726
@@ -1,19 +1,33 @@
|
||||
import { createEvents } from 'ics'
|
||||
import { createEvents, EventStatus } from 'ics'
|
||||
import { BookingDocument } from '../db/booking'
|
||||
import { BOOKING_STATUS } from '../db/bookingStatus'
|
||||
import { getBaseURL } from './url'
|
||||
|
||||
function convertDay(value: string): [number, number, number] {
|
||||
const parts = value.split('-')
|
||||
if (parts.length !== 3) {
|
||||
throw new Error('faile converting day')
|
||||
}
|
||||
return [Number(parts[0]), Number(parts[1]), Number(parts[2])]
|
||||
}
|
||||
|
||||
export function generateBookedCalendar(bookings: BookingDocument[]) {
|
||||
const events = bookings.map((booking) => ({
|
||||
start: convertDay(booking.days[0]),
|
||||
end: convertDay(booking.days[booking.days.length - 1]),
|
||||
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('-'),
|
||||
Link: ${getBaseURL()}/booking/${booking.uuid}`,
|
||||
status:
|
||||
booking.status === BOOKING_STATUS.CONFIRMED
|
||||
? ('CONFIRMED' as EventStatus)
|
||||
: ('TENTATIVE' as EventStatus),
|
||||
}))
|
||||
// ts-ignore
|
||||
|
||||
const { error, value } = createEvents(events)
|
||||
|
||||
if (error) {
|
||||
throw new Error(error)
|
||||
throw error
|
||||
}
|
||||
|
||||
return value
|
||||
|
||||
Reference in New Issue
Block a user