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.

Update coupon-deleted.ts

Kiran Ka1f1fedcc6de
diff --git a/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts b/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts
index fc194167e9..7c999c0085 100644
--- a/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts
+++ b/apps/web/app/(ee)/api/stripe/integration/webhook/coupon-deleted.ts
@@ -39,11 +39,7 @@ export async function couponDeleted(event: Stripe.Event) {
OR: [{ couponId: coupon.id }, { couponTestId: coupon.id }],
},
include: {
- partnerGroup: {
- select: {
- id: true,
- },
- },
+ partnerGroup: true,
},
});
@@ -52,25 +48,20 @@ export async function couponDeleted(event: Stripe.Event) {
}
const discountIds = discounts.map((d) => d.id);
- const groupIds = discounts
- .map((d) => d.partnerGroup?.id)
- .filter(Boolean) as string[];
await prisma.$transaction(async (tx) => {
- if (groupIds.length > 0) {
+ if (discountIds.length > 0) {
await tx.partnerGroup.updateMany({
where: {
- id: {
- in: groupIds,
+ discountId: {
+ in: discountIds,
},
},
data: {
discountId: null,
},
});
- }
- if (discountIds.length > 0) {
await tx.programEnrollment.updateMany({
where: {
discountId: {
@@ -107,6 +98,10 @@ export async function couponDeleted(event: Stripe.Event) {
role: "owner",
});
+ const groupIds = discounts
+ .map((d) => d.partnerGroup?.id)
+ .filter(Boolean) as string[];
+
await Promise.allSettled([
...groupIds.map((groupId) =>
qstash.publishJSON({