enable bill storing

This commit is contained in:
Thomas Ruoff
2020-10-05 00:09:05 +02:00
committed by Thomas Ruoff
parent df6ec51af9
commit ec1b2e9629
7 changed files with 152 additions and 109 deletions

View File

@@ -0,0 +1,27 @@
import { NextApiRequest, NextApiResponse } from 'next'
import { getBookings } from '../../db/index'
import { generateBookedCalendar } from '../../helpers/ical'
export default async function useHandler(
req: NextApiRequest,
res: NextApiResponse
) {
const { method } = req
switch (method) {
case 'GET':
const bookings = await getBookings()
const ical = generateBookedCalendar(bookings)
res.statusCode = 200
res.setHeader('Content-Type', 'text/calendar;charset=utf-8')
res.setHeader(
'Content-Disposition',
'attachment; filename="pfadi-bussle-buchungen.ics"'
)
res.send(ical)
break
default:
res.setHeader('Allow', ['GET'])
res.status(405).end(`Method ${method} Not Allowed`)
}
}