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 },
}
}

View File

@@ -1,6 +1,6 @@
import { Booking } from '@prisma/client';
import { google } from 'googleapis'
import { getBaseURL } from '../helpers/url'
import { Booking } from '../db/booking'
import { getDays, getNextDay, dateFormatBackend } from '../helpers/date'
import { log } from '../helpers/log'
@@ -39,15 +39,15 @@ export async function getBookedDays() {
.filter((event) => !!event.start.date)
.flatMap((event) =>
getDays({
startDate: new Date(event.start.date),
endDate: new Date(event.end.date),
startDate: event.start.date,
endDate: event.end.date,
endDateExclusive: true,
})
)
)
}
function getSummary(booking: Partial<Booking>): string {
function getSummary(booking: Booking): string {
let summary = ''
if (booking.org) {
@@ -59,13 +59,13 @@ function getSummary(booking: Partial<Booking>): string {
return summary
}
function getDescription(booking: Booking): string {
function getDescription(booking: Booking) {
const bookingUrl = `${getBaseURL()}/admin/booking/${booking.uuid}`
return `Managelink ${bookingUrl}`
}
export async function createCalendarEvent(booking: Booking): Promise<Booking> {
export async function createCalendarEvent(booking: Booking) {
const exclusiveEndDate = dateFormatBackend(
getNextDay(new Date(booking.endDate))
)
@@ -85,7 +85,7 @@ export async function createCalendarEvent(booking: Booking): Promise<Booking> {
return booking
}
export async function deleteCalendarEvent(booking: Booking) {
export async function deleteCalendarEvent(booking: { calendarEventId: string }) {
await calendar.events.delete({
calendarId,
eventId: booking.calendarEventId,
@@ -96,11 +96,11 @@ export async function deleteCalendarEvent(booking: Booking) {
booking.calendarEventId = null
}
//export async function patchCalendarEvent(booking: { calendarEventId: string } & Partial<Booking> ) : Promise<Booking> {
// const response = await calendar.events.patch({
// calendarId,
// eventId: booking.calendarEventId,
// });
//
// return booking;
//}
export async function patchCalendarEvent(booking: Booking ) {
await calendar.events.patch({
calendarId,
eventId: booking.calendarEventId,
});
return booking;
}