mirror of
https://github.com/hanzoai/calendar.git
synced 2026-09-24 22:42:24 +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
32 lines
1.5 KiB
TypeScript
32 lines
1.5 KiB
TypeScript
import { getCalendar } from "@calcom/app-store/_utils/getCalendar";
|
|
import { FeaturesRepository } from "@calcom/features/flags/features.repository";
|
|
import { getCredentialForCalendarCache } from "@calcom/app-store/delegationCredential";
|
|
import logger from "@calcom/lib/logger";
|
|
import { safeStringify } from "@calcom/lib/safeStringify";
|
|
import prisma from "@calcom/prisma";
|
|
import type { Calendar } from "@calcom/types/Calendar";
|
|
|
|
import { CalendarCacheRepository } from "./calendar-cache.repository";
|
|
import type { ICalendarCacheRepository } from "./calendar-cache.repository.interface";
|
|
import { CalendarCacheRepositoryMock } from "./calendar-cache.repository.mock";
|
|
|
|
const log = logger.getSubLogger({ prefix: ["CalendarCache"] });
|
|
|
|
export class CalendarCache {
|
|
static async initFromCredentialId(credentialId: number): Promise<ICalendarCacheRepository> {
|
|
log.debug("initFromCredentialId", safeStringify({ credentialId }));
|
|
const credentialForCalendarCache = await getCredentialForCalendarCache({ credentialId });
|
|
|
|
const calendarForCalendarCache = await getCalendar(credentialForCalendarCache);
|
|
return await CalendarCache.init(calendarForCalendarCache);
|
|
}
|
|
static async init(calendar: Calendar | null): Promise<ICalendarCacheRepository> {
|
|
const featureRepo = new FeaturesRepository(prisma);
|
|
const isCalendarCacheEnabledGlobally = await featureRepo.checkIfFeatureIsEnabledGlobally(
|
|
"calendar-cache"
|
|
);
|
|
if (isCalendarCacheEnabledGlobally) return new CalendarCacheRepository(calendar);
|
|
return new CalendarCacheRepositoryMock();
|
|
}
|
|
}
|