* WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * Update CalendarService.ts * Type fixes * WIP * fix: improve cache hits * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Update CalendarService.ts * Feedback * Update CalendarService.ts * Update CalendarService.ts * Update _router.ts * feedback * WIP * WIP * Update schema.prisma * feedback * typefixes * Update Calendar.d.ts * fix: watches when adding a calendar * Discard changes to packages/app-store/googlecalendar/api/add.ts * WIP Signed-off-by: Omar López <zomars@me.com> * WIP Signed-off-by: Omar López <zomars@me.com> * WP Signed-off-by: Omar López <zomars@me.com> * Update calendar.ts * Update calendar.ts * Update callback.ts * Update callback.ts * Conflicts * WIP * WIP * Update CalendarService.ts * Cleanup * Discard changes to packages/features/settings/layouts/SettingsLayout.tsx * Update calendar-cache.repository.ts * WIP * Update getSelectedCalendarsToWatch.sql * WIP * Update CalendarService.ts * Cleanup * Discard changes to packages/app-store/googlecalendar/lib/CalendarService.ts * Create CalendarService.wip.ts * WIP * Update CalendarService.ts * Update getSelectedCalendarsToWatch.sql * Delete CalendarService.wip.ts * test updates * cleanup Signed-off-by: Omar López <zomars@me.com> * Update CalendarService.test.ts * Update CalendarService.ts * type fixes * Update OAuthManager.ts * Update CalendarService.ts * Almost there * Update CalendarService.test.ts * Update calendar.ts * Update callback.ts * Update toggleFeatureFlag.handler.ts * fix: feedback * Update getSelectedCalendarsToWatch.sql * Fix unit tests --------- Signed-off-by: Omar López <zomars@me.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
37 lines
1.0 KiB
TypeScript
37 lines
1.0 KiB
TypeScript
import logger from "@calcom/lib/logger";
|
|
import type { PrismaClient } from "@calcom/prisma";
|
|
|
|
import type { TrpcSessionUser } from "../../../trpc";
|
|
import type { TAdminToggleFeatureFlagSchema } from "./toggleFeatureFlag.schema";
|
|
|
|
type GetOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
prisma: PrismaClient;
|
|
};
|
|
input: TAdminToggleFeatureFlagSchema;
|
|
};
|
|
|
|
export const toggleFeatureFlagHandler = async (opts: GetOptions) => {
|
|
const { ctx, input } = opts;
|
|
const { prisma, user } = ctx;
|
|
const { slug, enabled } = input;
|
|
await handleFeatureToggle(opts);
|
|
return prisma.feature.update({
|
|
where: { slug },
|
|
data: { enabled, updatedBy: user.id },
|
|
});
|
|
};
|
|
|
|
export default toggleFeatureFlagHandler;
|
|
|
|
async function handleFeatureToggle({ ctx, input }: GetOptions) {
|
|
const { prisma } = ctx;
|
|
const { slug, enabled } = input;
|
|
// If we're disabling the calendar cache, clear it
|
|
if (slug === "calendar-cache" && enabled === false) {
|
|
logger.info("Clearing calendar cache");
|
|
await prisma.calendarCache.deleteMany();
|
|
}
|
|
}
|