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 },
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user