* Revert "Revert "chore: Chore team metadata table + isOrganization migration from metadata (#12828)""
This reverts commit 2408338ed4.
* Remove constraint slug,isOrganization and reset migration
* fix: conflicts
* change schema to bust cache
* Fix issues reported by TS
* change schema to bust cache
* Review fixes
* Colaesce for orgAutoAcceptEmail as well
* Fix missing negation
---------
Co-authored-by: zomars <zomars@me.com>
Co-authored-by: Peer Richelsen <peeroke@gmail.com>
Co-authored-by: Keith Williams <keithwillcode@gmail.com>
Co-authored-by: Joe Au-Yeung <65426560+joeauyeung@users.noreply.github.com>
48 lines
1.4 KiB
TypeScript
48 lines
1.4 KiB
TypeScript
import { cancelTeamSubscriptionFromStripe } from "@calcom/features/ee/teams/lib/payments";
|
|
import { IS_TEAM_BILLING_ENABLED } from "@calcom/lib/constants";
|
|
import { deleteDomain } from "@calcom/lib/domainManager/organization";
|
|
import { isTeamOwner } from "@calcom/lib/server/queries/teams";
|
|
import { closeComDeleteTeam } from "@calcom/lib/sync/SyncServiceManager";
|
|
import { prisma } from "@calcom/prisma";
|
|
|
|
import { TRPCError } from "@trpc/server";
|
|
|
|
import type { TrpcSessionUser } from "../../../trpc";
|
|
import type { TDeleteInputSchema } from "./delete.schema";
|
|
|
|
type DeleteOptions = {
|
|
ctx: {
|
|
user: NonNullable<TrpcSessionUser>;
|
|
};
|
|
input: TDeleteInputSchema;
|
|
};
|
|
|
|
export const deleteHandler = async ({ ctx, input }: DeleteOptions) => {
|
|
if (!(await isTeamOwner(ctx.user?.id, input.teamId))) throw new TRPCError({ code: "UNAUTHORIZED" });
|
|
|
|
if (IS_TEAM_BILLING_ENABLED) await cancelTeamSubscriptionFromStripe(input.teamId);
|
|
|
|
const deletedTeam = await prisma.$transaction(async (tx) => {
|
|
// delete all memberships
|
|
await tx.membership.deleteMany({
|
|
where: {
|
|
teamId: input.teamId,
|
|
},
|
|
});
|
|
|
|
const deletedTeam = await tx.team.delete({
|
|
where: {
|
|
id: input.teamId,
|
|
},
|
|
});
|
|
return deletedTeam;
|
|
});
|
|
|
|
if (deletedTeam?.isOrganization && deletedTeam.slug) deleteDomain(deletedTeam.slug);
|
|
|
|
// Sync Services: Close.cm
|
|
closeComDeleteTeam(deletedTeam);
|
|
};
|
|
|
|
export default deleteHandler;
|