From b146b807785be684ed72d5023250f884ac418ec5 Mon Sep 17 00:00:00 2001 From: nicolas Date: Thu, 15 Jul 2021 23:34:55 +0200 Subject: [PATCH] Fixed signature --- lib/calendarClient.ts | 4 +++- pages/api/cancel.ts | 45 +++++++++++++++++++------------------------ 2 files changed, 23 insertions(+), 26 deletions(-) diff --git a/lib/calendarClient.ts b/lib/calendarClient.ts index 41720971f6..f9c4dfd5a0 100644 --- a/lib/calendarClient.ts +++ b/lib/calendarClient.ts @@ -498,7 +498,9 @@ const calendars = (withCredentials): CalendarApiAdapter[] => .filter(Boolean); const getBusyCalendarTimes = (withCredentials, dateFrom, dateTo, selectedCalendars) => - Promise.all(calendars(withCredentials).map((c) => c.getAvailability(selectedCalendars))).then((results) => { + Promise.all( + calendars(withCredentials).map((c) => c.getAvailability(dateFrom, dateTo, selectedCalendars)) + ).then((results) => { return results.reduce((acc, availability) => acc.concat(availability), []); }); diff --git a/pages/api/cancel.ts b/pages/api/cancel.ts index 90ef2f43eb..e3c96f98c5 100644 --- a/pages/api/cancel.ts +++ b/pages/api/cancel.ts @@ -1,7 +1,7 @@ -import prisma from '../../lib/prisma'; -import {deleteEvent} from "../../lib/calendarClient"; -import async from 'async'; -import {deleteMeeting} from "../../lib/videoClient"; +import prisma from "../../lib/prisma"; +import { deleteEvent } from "../../lib/calendarClient"; +import async from "async"; +import { deleteMeeting } from "../../lib/videoClient"; export default async function handler(req, res) { if (req.method == "POST") { @@ -15,36 +15,36 @@ export default async function handler(req, res) { id: true, user: { select: { - credentials: true - } + credentials: true, + }, }, attendees: true, references: { select: { uid: true, - type: true - } - } - } + type: true, + }, + }, + }, }); const apiDeletes = async.mapLimit(bookingToDelete.user.credentials, 5, async (credential) => { const bookingRefUid = bookingToDelete.references.filter((ref) => ref.type === credential.type)[0].uid; - if(credential.type.endsWith("_calendar")) { + if (credential.type.endsWith("_calendar")) { return await deleteEvent(credential, bookingRefUid); - } else if(credential.type.endsWith("_video")) { + } else if (credential.type.endsWith("_video")) { return await deleteMeeting(credential, bookingRefUid); } }); const attendeeDeletes = prisma.attendee.deleteMany({ where: { - bookingId: bookingToDelete.id - } + bookingId: bookingToDelete.id, + }, }); const bookingReferenceDeletes = prisma.bookingReference.deleteMany({ where: { - bookingId: bookingToDelete.id - } + bookingId: bookingToDelete.id, + }, }); const bookingDeletes = prisma.booking.delete({ where: { @@ -52,17 +52,12 @@ export default async function handler(req, res) { }, }); - await Promise.all([ - apiDeletes, - attendeeDeletes, - bookingReferenceDeletes, - bookingDeletes - ]); + await Promise.all([apiDeletes, attendeeDeletes, bookingReferenceDeletes, bookingDeletes]); //TODO Perhaps send emails to user and client to tell about the cancellation - res.status(200).json({message: 'Booking successfully deleted.'}); + res.status(200).json({ message: "Booking successfully deleted." }); } else { - res.status(405).json({message: 'This endpoint only accepts POST requests.'}); + res.status(405).json({ message: "This endpoint only accepts POST requests." }); } -} \ No newline at end of file +}