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 partner image in cron cleanup

Steven Tey83ee7f6c8050
diff --git a/apps/web/lib/api/partners/delete-partner.ts b/apps/web/lib/api/partners/delete-partner.ts
index 69dea425f2..2a5e64f0ce 100644
--- a/apps/web/lib/api/partners/delete-partner.ts
+++ b/apps/web/lib/api/partners/delete-partner.ts
@@ -1,7 +1,11 @@
+import { storage } from "@/lib/storage";
import { stripe } from "@/lib/stripe";
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
+// currently only used for the cron/cleanup job
export async function deletePartner({ partnerId }: { partnerId: string }) {
const partner = await prisma.partner.findUnique({
where: {
@@ -62,4 +66,8 @@ export async function deletePartner({ partnerId }: { partnerId: string }) {
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}/`, ""));
+ }
}