Merge pull request #413 from emrysal/bugfix/fix-zoom-calendar-conflict
This commit is contained in:
commit
da98a1ff1d
1 changed files with 8 additions and 24 deletions
|
@ -1,7 +1,7 @@
|
||||||
import type { NextApiRequest, NextApiResponse } from "next";
|
import type { NextApiRequest, NextApiResponse } from "next";
|
||||||
import prisma from "../../../lib/prisma";
|
import prisma from "@lib/prisma";
|
||||||
import { getBusyCalendarTimes } from "../../../lib/calendarClient";
|
import { getBusyCalendarTimes } from "@lib/calendarClient";
|
||||||
import { getBusyVideoTimes } from "../../../lib/videoClient";
|
import { getBusyVideoTimes } from "@lib/videoClient";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
|
|
||||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||||
|
@ -25,39 +25,23 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
const hasCalendarIntegrations =
|
const calendarBusyTimes = await getBusyCalendarTimes(
|
||||||
currentUser.credentials.filter((cred) => cred.type.endsWith("_calendar")).length > 0;
|
|
||||||
const hasVideoIntegrations =
|
|
||||||
currentUser.credentials.filter((cred) => cred.type.endsWith("_video")).length > 0;
|
|
||||||
|
|
||||||
const calendarAvailability = await getBusyCalendarTimes(
|
|
||||||
currentUser.credentials,
|
currentUser.credentials,
|
||||||
req.query.dateFrom,
|
req.query.dateFrom,
|
||||||
req.query.dateTo,
|
req.query.dateTo,
|
||||||
selectedCalendars
|
selectedCalendars
|
||||||
);
|
);
|
||||||
const videoAvailability = await getBusyVideoTimes(
|
const videoBusyTimes = await getBusyVideoTimes(
|
||||||
currentUser.credentials,
|
currentUser.credentials,
|
||||||
req.query.dateFrom,
|
req.query.dateFrom,
|
||||||
req.query.dateTo
|
req.query.dateTo
|
||||||
);
|
);
|
||||||
|
calendarBusyTimes.push(...videoBusyTimes);
|
||||||
|
|
||||||
let commonAvailability = [];
|
const bufferedBusyTimes = calendarBusyTimes.map((a) => ({
|
||||||
|
|
||||||
if (hasCalendarIntegrations && hasVideoIntegrations) {
|
|
||||||
commonAvailability = calendarAvailability.filter((availability) =>
|
|
||||||
videoAvailability.includes(availability)
|
|
||||||
);
|
|
||||||
} else if (hasVideoIntegrations) {
|
|
||||||
commonAvailability = videoAvailability;
|
|
||||||
} else if (hasCalendarIntegrations) {
|
|
||||||
commonAvailability = calendarAvailability;
|
|
||||||
}
|
|
||||||
|
|
||||||
commonAvailability = commonAvailability.map((a) => ({
|
|
||||||
start: dayjs(a.start).subtract(currentUser.bufferTime, "minute").toString(),
|
start: dayjs(a.start).subtract(currentUser.bufferTime, "minute").toString(),
|
||||||
end: dayjs(a.end).add(currentUser.bufferTime, "minute").toString(),
|
end: dayjs(a.end).add(currentUser.bufferTime, "minute").toString(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
res.status(200).json(commonAvailability);
|
res.status(200).json(bufferedBusyTimes);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue