2023-07-25 22:00:21 +00:00
|
|
|
import { z } from "zod";
|
|
|
|
|
2023-07-07 12:55:21 +00:00
|
|
|
import { authedAdminProcedure } from "../../../procedures/authedProcedure";
|
|
|
|
import { router } from "../../../trpc";
|
|
|
|
import { ZListMembersSchema } from "./listPaginated.schema";
|
|
|
|
import { ZAdminPasswordResetSchema } from "./sendPasswordReset.schema";
|
|
|
|
|
|
|
|
type AdminRouterHandlerCache = {
|
|
|
|
listPaginated?: typeof import("./listPaginated.handler").listPaginatedHandler;
|
|
|
|
sendPasswordReset?: typeof import("./sendPasswordReset.handler").sendPasswordResetHandler;
|
|
|
|
};
|
|
|
|
|
|
|
|
const UNSTABLE_HANDLER_CACHE: AdminRouterHandlerCache = {};
|
|
|
|
|
|
|
|
export const adminRouter = router({
|
|
|
|
listPaginated: authedAdminProcedure.input(ZListMembersSchema).query(async ({ ctx, input }) => {
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.listPaginated) {
|
|
|
|
UNSTABLE_HANDLER_CACHE.listPaginated = await import("./listPaginated.handler").then(
|
|
|
|
(mod) => mod.listPaginatedHandler
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unreachable code but required for type safety
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.listPaginated) {
|
|
|
|
throw new Error("Failed to load handler");
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNSTABLE_HANDLER_CACHE.listPaginated({
|
|
|
|
ctx,
|
|
|
|
input,
|
|
|
|
});
|
|
|
|
}),
|
|
|
|
sendPasswordReset: authedAdminProcedure
|
|
|
|
.input(ZAdminPasswordResetSchema)
|
|
|
|
.mutation(async ({ ctx, input }) => {
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.sendPasswordReset) {
|
|
|
|
UNSTABLE_HANDLER_CACHE.sendPasswordReset = await import("./sendPasswordReset.handler").then(
|
|
|
|
(mod) => mod.sendPasswordResetHandler
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Unreachable code but required for type safety
|
|
|
|
if (!UNSTABLE_HANDLER_CACHE.sendPasswordReset) {
|
|
|
|
throw new Error("Failed to load handler");
|
|
|
|
}
|
|
|
|
|
|
|
|
return UNSTABLE_HANDLER_CACHE.sendPasswordReset({
|
|
|
|
ctx,
|
|
|
|
input,
|
|
|
|
});
|
|
|
|
}),
|
2023-07-25 22:00:21 +00:00
|
|
|
toggleFeatureFlag: 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 },
|
|
|
|
});
|
|
|
|
}),
|
2023-07-07 12:55:21 +00:00
|
|
|
});
|