Skip to content

armgit / dub

Public Imported from GitHub
0

The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.

Delete delete-partner.ts

Kiran K0d3a7b6ba79a
diff --git a/apps/web/lib/api/partners/delete-partner.ts b/apps/web/lib/api/partners/delete-partner.ts
deleted file mode 100644
index 05b818139c..0000000000
--- a/apps/web/lib/api/partners/delete-partner.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-import { storage } from "@/lib/storage";
-import { stripe } from "@/lib/stripe";
-import { WorkspaceProps } from "@/lib/types";
-import { prisma } from "@dub/prisma";
-import { R2_URL } from "@dub/utils";
-import { bulkDeleteLinks } from "../links/bulk-delete-links";
-
-// delete partner and all associated links, customers, payouts, and commissions
-// Not using this anymore
-export async function deletePartner({
- partnerId,
- workspace,
-}: {
- partnerId: string;
- workspace: Pick<WorkspaceProps, "id" | "stripeConnectId">;
-}) {
- const partner = await prisma.partner.findUnique({
- where: {
- id: partnerId,
- },
- include: {
- programs: {
- select: {
- links: true,
- },
- },
- },
- });
-
- if (!partner) {
- console.error(`Partner with id ${partnerId} not found.`);
- return;
- }
-
- const links = partner.programs.length > 0 ? partner.programs[0].links : [];
-
- if (links.length > 0) {
- await prisma.customer.deleteMany({
- where: {
- linkId: {
- in: links.map((link) => link.id),
- },
- },
- });
-
- await bulkDeleteLinks({
- links,
- workspace,
- });
-
- await prisma.link.deleteMany({
- where: {
- id: {
- in: links.map((link) => link.id),
- },
- },
- });
- }
-
- await prisma.commission.deleteMany({
- where: {
- partnerId: partner.id,
- },
- });
-
- await prisma.payout.deleteMany({
- where: {
- partnerId: partner.id,
- },
- });
-
- await prisma.partner.delete({
- where: {
- id: partner.id,
- },
- });
-
- if (partner.stripeConnectId) {
- await stripe.accounts.del(partner.stripeConnectId);
- }
-
- if (partner.image && partner.image.startsWith(R2_URL)) {
- await storage.delete(partner.image.replace(`${R2_URL}/`, ""));
- }
-}