Files
calendar/packages/core/getBusyTimes.ts
T
Syed Ali ShahbazGitHubPeer Richelsenkodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>zomars
ee02112a7c Dynamic Links re-integrate with availability logic (#3687)
* -re init dynamic links

* typing fix 001

* added missing div closing tag

* added necessary DB column pull to satisfy Type errors

* further type fixes

* WIP

* removed console logs

* some revert

* WIP

* another approach

* enabled dynamic links availability fetch

* Added users to eventTypeObject for consistency

* WIP: Moving user and changing map item name

* Fix user list call

* Removed explicit User type in map

* modify default user attributes

* adds explicit users to EventTypeObject in teams

* Updated availability page

* Updates Availability

* Futher availability change

* Remove explicit user type from slot router

* more fixes

* more fixes WIP

* cleaning up more errors WIP

* object assign used for typesafety

* added check if dynamic booking is allowed by all users

* cleaned up console logs

* clean up

* Improvement

* resolving suggestions by alex

* changes requested by Omar

* Filter out empty usernames instead of accepting null

Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
Co-authored-by: zomars <zomars@me.com>
2022-08-12 19:29:29 +00:00

64 lines
2.2 KiB
TypeScript

import { BookingStatus, Credential, SelectedCalendar } from "@prisma/client";
import { getBusyCalendarTimes } from "@calcom/core/CalendarManager";
import logger from "@calcom/lib/logger";
import { performance } from "@calcom/lib/server/perfObserver";
import prisma from "@calcom/prisma";
import type { EventBusyDetails } from "@calcom/types/Calendar";
export async function getBusyTimes(params: {
credentials: Credential[];
userId: number;
eventTypeId?: number;
startTime: string;
endTime: string;
selectedCalendars: SelectedCalendar[];
}) {
const { credentials, userId, eventTypeId, startTime, endTime, selectedCalendars } = params;
logger.silly(
`Checking Busy time from Cal Bookings in range ${startTime} to ${endTime} for input ${JSON.stringify({
userId,
eventTypeId,
status: BookingStatus.ACCEPTED,
})}`
);
const startPrismaBookingGet = performance.now();
const busyTimes: EventBusyDetails[] = await prisma.booking
.findMany({
where: {
userId,
eventTypeId,
startTime: { gte: new Date(startTime) },
endTime: { lte: new Date(endTime) },
status: {
in: [BookingStatus.ACCEPTED],
},
},
select: {
id: true,
startTime: true,
endTime: true,
title: true,
},
})
.then((bookings) =>
bookings.map(({ startTime, endTime, title }) => ({ end: endTime, start: startTime, title }))
);
logger.silly(`Busy Time from Cal Bookings ${JSON.stringify(busyTimes)}`);
const endPrismaBookingGet = performance.now();
logger.debug(`prisma booking get took ${endPrismaBookingGet - startPrismaBookingGet}ms`);
if (credentials?.length > 0) {
const calendarBusyTimes = await getBusyCalendarTimes(credentials, startTime, endTime, selectedCalendars);
busyTimes.push(...calendarBusyTimes); /*
// TODO: Disabled until we can filter Zoom events by date. Also this is adding too much latency.
const videoBusyTimes = (await getBusyVideoTimes(credentials)).filter(notEmpty);
console.log("videoBusyTimes", videoBusyTimes);
busyTimes.push(...videoBusyTimes);
*/
}
return busyTimes;
}
export default getBusyTimes;