2023-03-25 00:59:04 +00:00
|
|
|
import { z } from "zod";
|
|
|
|
|
2023-05-09 19:27:05 +00:00
|
|
|
import { authedAdminProcedure } from "@calcom/trpc/server/procedures/authedProcedure";
|
|
|
|
import publicProcedure from "@calcom/trpc/server/procedures/publicProcedure";
|
|
|
|
import { router } from "@calcom/trpc/server/trpc";
|
2023-03-25 00:59:04 +00:00
|
|
|
|
|
|
|
import { getFeatureFlagMap } from "./utils";
|
|
|
|
|
|
|
|
export const featureFlagRouter = router({
|
|
|
|
list: publicProcedure.query(async ({ ctx }) => {
|
|
|
|
const { prisma } = ctx;
|
|
|
|
return prisma.feature.findMany({
|
|
|
|
orderBy: { slug: "asc" },
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
map: publicProcedure.query(async ({ ctx }) => {
|
|
|
|
const { prisma } = ctx;
|
|
|
|
return getFeatureFlagMap(prisma);
|
|
|
|
}),
|
|
|
|
toggle: authedAdminProcedure
|
|
|
|
.input(z.object({ slug: z.string(), enabled: z.boolean() }))
|
|
|
|
.mutation(({ ctx, input }) => {
|
|
|
|
const { prisma, user } = ctx;
|
|
|
|
const { slug, enabled } = input;
|
|
|
|
return prisma.feature.update({
|
|
|
|
where: { slug },
|
|
|
|
data: { enabled, updatedBy: user.id },
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
});
|