mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-04 15:07:13 +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 { 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[]) {
|
export function generateBookedCalendar(bookings: BookingDocument[]) {
|
||||||
const events = bookings.map((booking) => ({
|
const events = bookings.map((booking) => ({
|
||||||
|
start: convertDay(booking.days[0]),
|
||||||
|
end: convertDay(booking.days[booking.days.length - 1]),
|
||||||
title: `Buchung ${booking.booker.name}`,
|
title: `Buchung ${booking.booker.name}`,
|
||||||
description: `UUID: ${booking.uuid}
|
description: `UUID: ${booking.uuid}
|
||||||
Link: http://${process.env.VERCEL_URL}/booking/${booking.uuid}`,
|
Link: ${getBaseURL()}/booking/${booking.uuid}`,
|
||||||
start: booking.days[0].split('-'),
|
status:
|
||||||
end: booking.days[booking.days.length - 1].split('-'),
|
booking.status === BOOKING_STATUS.CONFIRMED
|
||||||
|
? ('CONFIRMED' as EventStatus)
|
||||||
|
: ('TENTATIVE' as EventStatus),
|
||||||
}))
|
}))
|
||||||
// ts-ignore
|
|
||||||
const { error, value } = createEvents(events)
|
const { error, value } = createEvents(events)
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
throw new Error(error)
|
throw error
|
||||||
}
|
}
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|||||||
Reference in New Issue
Block a user