add an admin overview page

This commit is contained in:
Thomas Ruoff
2020-11-23 23:49:13 +01:00
parent c7cd252506
commit 4db3eadaeb
2 changed files with 118 additions and 1 deletions

View File

@@ -1,4 +1,6 @@
import { getBookingByUUID } from '../db/index'
import { startOfYear } from 'date-fns'
import { nowInTz } from '../helpers/date'
import { getBookingByUUID, getBookings } from '../db/index'
export interface ServerSideBooking {
props: {
@@ -6,6 +8,30 @@ export interface ServerSideBooking {
}
}
export interface ServerSideRecentBooking {
props: {
bookings: object[]
}
}
export const getServerSideRecentBookings = async (): Promise<
ServerSideRecentBooking
> => {
const bookings = await getBookings({
startDateGreaterThan: startOfYear(nowInTz()).toISOString(),
})
// TODO: hack, not sure why _id is not serilizable
const bookingsJSON = JSON.parse(
JSON.stringify(bookings.map((b) => b.toJSON()))
) as object[]
return {
props: {
bookings: bookingsJSON,
},
}
}
export const getServerSideBooking = async (
context: any
): Promise<ServerSideBooking> => {