mirror of
https://github.com/hanzoai/calendar.git
synced 2026-10-30 14:46:43 +00:00
* move delegation credential repository to features * mv credential repository to features * update imports * mv * fix * fix * fix * fix * fix * update imports * update imports * update eslint rule * fix * fix * mv getConnectedDestinationCalendars * fix import errors * mv getCalendarsEvents * remove getUsersCredentials * wip * revert eslint rule change for now * fix type checks * fix * format * cleanup * fix * fix * fix * fix * fix tests * migrate getUserAvailability * migrate * fix tests * fix type checks * fix * fix * migrate crmManager * update imports * migrate raqbUtils to appstore * migrate getLuckyUser to features * migrate findTeamMembersMatchingAttributeLogic to appstore * update imports * fix * fix * fix test * fix unit tests * fix * fix * add eslint config
43 lines
1.5 KiB
TypeScript
43 lines
1.5 KiB
TypeScript
import { CalendarCacheRepository } from "@calcom/features/calendar-cache/calendar-cache.repository";
|
|
import { getConnectedDestinationCalendarsAndEnsureDefaultsInDb } from "@calcom/features/calendars/lib/getConnectedDestinationCalendars";
|
|
import { prisma } from "@calcom/prisma";
|
|
import type { TrpcSessionUser } from "@calcom/trpc/server/types";
|
|
|
|
import type { TConnectedCalendarsInputSchema } from "./connectedCalendars.schema";
|
|
|
|
type ConnectedCalendarsOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TConnectedCalendarsInputSchema;
|
|
};
|
|
|
|
export const connectedCalendarsHandler = async ({ ctx, input }: ConnectedCalendarsOptions) => {
|
|
const { user } = ctx;
|
|
const onboarding = input?.onboarding || false;
|
|
|
|
const { connectedCalendars, destinationCalendar } =
|
|
await getConnectedDestinationCalendarsAndEnsureDefaultsInDb({
|
|
user,
|
|
onboarding,
|
|
eventTypeId: input?.eventTypeId ?? null,
|
|
prisma,
|
|
});
|
|
|
|
const credentialIds = connectedCalendars.map((cal) => cal.credentialId);
|
|
const cacheRepository = new CalendarCacheRepository();
|
|
const cacheStatuses = await cacheRepository.getCacheStatusByCredentialIds(credentialIds);
|
|
|
|
const cacheStatusMap = new Map(cacheStatuses.map((cache) => [cache.credentialId, cache.updatedAt]));
|
|
|
|
const enrichedConnectedCalendars = connectedCalendars.map((calendar) => ({
|
|
...calendar,
|
|
cacheUpdatedAt: cacheStatusMap.get(calendar.credentialId) || null,
|
|
}));
|
|
|
|
return {
|
|
connectedCalendars: enrichedConnectedCalendars,
|
|
destinationCalendar,
|
|
};
|
|
};
|