From 78de56b7f5cbf54f415a2806db86793b54c26329 Mon Sep 17 00:00:00 2001 From: Alex van Andel Date: Tue, 3 Aug 2021 10:14:20 +0000 Subject: [PATCH] Missing dayjs().isBetween plugin + format Z explicitly --- pages/api/book/[user].ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/pages/api/book/[user].ts b/pages/api/book/[user].ts index 2a5c2273de..2151778330 100644 --- a/pages/api/book/[user].ts +++ b/pages/api/book/[user].ts @@ -14,12 +14,14 @@ import logger from "../../../lib/logger"; import utc from "dayjs/plugin/utc"; import timezone from "dayjs/plugin/timezone"; +import isBetween from "dayjs/plugin/isBetween"; import dayjsBusinessDays from "dayjs-business-days"; import { Exception } from "handlebars"; import EventOrganizerRequestMail from "@lib/emails/EventOrganizerRequestMail"; dayjs.extend(dayjsBusinessDays); dayjs.extend(utc); +dayjs.extend(isBetween); dayjs.extend(timezone); const translator = short(); @@ -28,7 +30,6 @@ const log = logger.getChildLogger({ prefix: ["[api] book:user"] }); function isAvailable(busyTimes, time, length) { // Check for conflicts let t = true; - if (Array.isArray(busyTimes) && busyTimes.length > 0) { busyTimes.forEach((busyTime) => { const startTime = dayjs(busyTime.start); @@ -312,8 +313,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) const calendarAvailability = await getBusyCalendarTimes( currentUser.credentials, - dayjs(req.body.start).startOf("day").utc().format(), - dayjs(req.body.end).endOf("day").utc().format(), + dayjs(req.body.start).startOf("day").utc().format("YYYY-MM-DDTHH:mm:ss[Z]"), + dayjs(req.body.end).endOf("day").utc().format("YYYY-MM-DDTHH:mm:ss[Z]"), selectedCalendars ); const videoAvailability = await getBusyVideoTimes( @@ -412,7 +413,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) try { isAvailableToBeBooked = isAvailable(commonAvailability, req.body.start, selectedEventType.length); - } catch { + } catch (e) { + console.log(e); log.debug({ message: "Unable set isAvailableToBeBooked. Using true. ", });