mirror of
https://github.com/tomru/pfadi-bussle.git
synced 2026-03-03 14:37:13 +01:00
switch to prisma
This commit is contained in:
@@ -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 },
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user