switch to prisma

This commit is contained in:
Thomas Ruoff
2022-10-11 11:43:32 +02:00
parent 41342475ba
commit 1ef9b14e95
28 changed files with 764 additions and 780 deletions

View File

@@ -1,39 +1,36 @@
import { Booking } from '@prisma/client';
import { startOfYear } from 'date-fns'
import { nowInTz } from '../helpers/date'
import { getBookingByUUID, getBookings } from '../db/index'
export type ServerSideBooking = {
props: {
booking: object
booking: Booking
}
}
export type ServerSideRecentBooking = {
props: {
bookings: object[]
bookings: Booking[]
}
}
export const getServerSideRecentBookings =
async (): Promise<ServerSideRecentBooking> => {
async () => {
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,
bookings: bookings,
},
}
}
export const getServerSideBooking = async (
context: any
): Promise<ServerSideBooking> => {
) => {
const {
res,
params: { uuid: uuids },
@@ -47,11 +44,7 @@ export const getServerSideBooking = async (
return { props: { booking: null } }
}
await booking.populate('bill')
// TODO: hack, not sure why _id is not serilizable
const bookingJSON = JSON.parse(JSON.stringify(booking.toJSON())) as object
return {
props: { booking: bookingJSON },
props: { booking },
}
}