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