bdd3b132d4
* Inital UI + layout setup * use booker approach of grid * event-select - sidebar + store work * adds get schedule by event-type-slug * Calendar toggle * Load schedule from event slug * Add busy events to calendar * useschedule * Store more event info than just slug * Add date override to calendar * Changes sizes on smaller screens * add event title as a tooltip * Ensure header navigation works * Stop navigator throwing errors on inital render * Correct br * Event duration fixes * Add getMoreInfo if user is authed with current request.username * Add calendar color map wip * Add WIP comments for coloured outlines * Revert more info changes * Calculate date override correctly * Add description option * Fix inital schedule data not being populated * Nudge overlap over to make it clearer * Fix disabled state * WIP on math logic * Event list overlapping events logic * NIT about width * i18n + manage calendars link * Delete old troubleshooter * Update packages/features/calendars/weeklyview/components/event/EventList.tsx * Remove t-slots * Fix i18n & install calendar action * sm:imrovments * NITS * Fix types * fix: back button * Month prop null as we control from query param * Add head SEO * Fix headseo import * Fix date override tests
79 lines
3.0 KiB
TypeScript
79 lines
3.0 KiB
TypeScript
import type { SelectedCalendar } from "@prisma/client";
|
|
|
|
import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
|
|
import logger from "@calcom/lib/logger";
|
|
import { getPiiFreeCredential, getPiiFreeSelectedCalendar } from "@calcom/lib/piiFreeData";
|
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
|
import { performance } from "@calcom/lib/server/perfObserver";
|
|
import type { EventBusyDate } from "@calcom/types/Calendar";
|
|
import type { CredentialPayload } from "@calcom/types/Credential";
|
|
|
|
const log = logger.getSubLogger({ prefix: ["getCalendarsEvents"] });
|
|
const getCalendarsEvents = async (
|
|
withCredentials: CredentialPayload[],
|
|
dateFrom: string,
|
|
dateTo: string,
|
|
selectedCalendars: SelectedCalendar[]
|
|
): Promise<EventBusyDate[][]> => {
|
|
const calendarCredentials = withCredentials
|
|
.filter((credential) => credential.type.endsWith("_calendar"))
|
|
// filter out invalid credentials - these won't work.
|
|
.filter((credential) => !credential.invalid);
|
|
|
|
const calendars = await Promise.all(calendarCredentials.map((credential) => getCalendar(credential)));
|
|
performance.mark("getBusyCalendarTimesStart");
|
|
const results = calendars.map(async (c, i) => {
|
|
/** Filter out nulls */
|
|
if (!c) return [];
|
|
/** We rely on the index so we can match credentials with calendars */
|
|
const { type, appId } = calendarCredentials[i];
|
|
/** We just pass the calendars that matched the credential type,
|
|
* TODO: Migrate credential type or appId
|
|
*/
|
|
const passedSelectedCalendars = selectedCalendars.filter((sc) => sc.integration === type);
|
|
if (!passedSelectedCalendars.length) return [];
|
|
/** We extract external Ids so we don't cache too much */
|
|
|
|
const selectedCalendarIds = passedSelectedCalendars.map((sc) => sc.externalId);
|
|
/** If we don't then we actually fetch external calendars (which can be very slow) */
|
|
performance.mark("eventBusyDatesStart");
|
|
log.debug(
|
|
`Getting availability for`,
|
|
safeStringify({
|
|
calendarService: c.constructor.name,
|
|
selectedCalendars: passedSelectedCalendars.map(getPiiFreeSelectedCalendar),
|
|
})
|
|
);
|
|
const eventBusyDates = await c.getAvailability(dateFrom, dateTo, passedSelectedCalendars);
|
|
performance.mark("eventBusyDatesEnd");
|
|
performance.measure(
|
|
`[getAvailability for ${selectedCalendarIds.join(", ")}][$1]'`,
|
|
"eventBusyDatesStart",
|
|
"eventBusyDatesEnd"
|
|
);
|
|
|
|
return eventBusyDates.map((a) => ({
|
|
...a,
|
|
source: `${appId}`,
|
|
}));
|
|
});
|
|
const awaitedResults = await Promise.all(results);
|
|
performance.mark("getBusyCalendarTimesEnd");
|
|
performance.measure(
|
|
`getBusyCalendarTimes took $1 for creds ${calendarCredentials.map((cred) => cred.id)}`,
|
|
"getBusyCalendarTimesStart",
|
|
"getBusyCalendarTimesEnd"
|
|
);
|
|
log.debug(
|
|
"Result",
|
|
safeStringify({
|
|
calendarCredentials: calendarCredentials.map(getPiiFreeCredential),
|
|
selectedCalendars: selectedCalendars.map(getPiiFreeSelectedCalendar),
|
|
calendarEvents: awaitedResults,
|
|
})
|
|
);
|
|
return awaitedResults;
|
|
};
|
|
|
|
export default getCalendarsEvents;
|