Co-authored-by: Alex van Andel <me@alexvanandel.com> Co-authored-by: Keith Williams <keithwillcode@gmail.com> Co-authored-by: Peer Richelsen <peeroke@gmail.com> Co-authored-by: Joe Au-Yeung <j.auyeung419@gmail.com> Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com> Co-authored-by: sean-brydon <55134778+sean-brydon@users.noreply.github.com> Co-authored-by: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com>
39 lines
931 B
TypeScript
39 lines
931 B
TypeScript
import jackson from "@calcom/features/ee/sso/lib/jackson";
|
|
import { canAccess } from "@calcom/features/ee/sso/lib/saml";
|
|
import prisma from "@calcom/prisma";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TrpcSessionUser } from "../../../trpc";
|
|
import type { ZDeleteInputSchema } from "./delete.schema";
|
|
|
|
type Options = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: ZDeleteInputSchema;
|
|
};
|
|
|
|
// Delete directory sync connection for a team
|
|
export const deleteHandler = async ({ ctx, input }: Options) => {
|
|
const { dsyncController } = await jackson();
|
|
|
|
const { message, access } = await canAccess(ctx.user, input.orgId);
|
|
|
|
if (!access) {
|
|
throw new TRPCError({
|
|
code: "BAD_REQUEST",
|
|
message,
|
|
});
|
|
}
|
|
|
|
await prisma.dSyncData.delete({
|
|
where: {
|
|
orgId: input.orgId || undefined,
|
|
},
|
|
});
|
|
await dsyncController.directories.delete(input.directoryId);
|
|
|
|
return null;
|
|
};
|