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.

wip

Kiran K10836c8a5804
diff --git a/apps/web/lib/actions/partners/ban-partner.ts b/apps/web/lib/actions/partners/ban-partner.ts
index 9c654fca34..7c4a258325 100644
--- a/apps/web/lib/actions/partners/ban-partner.ts
+++ b/apps/web/lib/actions/partners/ban-partner.ts
@@ -105,7 +105,8 @@ export const banPartnerAction = authActionClient
...links.map((link) =>
queueDiscountCodeDeletion({
- discountCodeId: link.discountCode?.id,
+ code: link.discountCode?.code,
+ stripeConnectId: workspace.stripeConnectId,
}),
),
diff --git a/apps/web/lib/actions/partners/bulk-ban-partners.ts b/apps/web/lib/actions/partners/bulk-ban-partners.ts
index 9da0a05128..28eabc30fc 100644
--- a/apps/web/lib/actions/partners/bulk-ban-partners.ts
+++ b/apps/web/lib/actions/partners/bulk-ban-partners.ts
@@ -132,7 +132,8 @@ export const bulkBanPartnersAction = authActionClient
await Promise.allSettled(
links.map((link) =>
queueDiscountCodeDeletion({
- discountCodeId: link.discountCode?.id,
+ code: link.discountCode?.code,
+ stripeConnectId: workspace.stripeConnectId,
}),
),
);
diff --git a/apps/web/lib/api/discounts/queue-discount-code-deletion.ts b/apps/web/lib/api/discounts/queue-discount-code-deletion.ts
index 390cff04c5..ad0265250e 100644
--- a/apps/web/lib/api/discounts/queue-discount-code-deletion.ts
+++ b/apps/web/lib/api/discounts/queue-discount-code-deletion.ts
@@ -6,74 +6,77 @@ const queue = qstash.queue({
queueName: "discount-code-deletion",
});
+interface Payload {
+ code: string | null | undefined;
+ stripeConnectId: string | null | undefined;
+}
+
// Triggered in the following cases:
// 1. When a discount is deleted
// 2. When coupon tracking is disabled for a discount
// 3. When a link is deleted that has a discount code associated with it
+// 4. When a partner is banned
+// 5. When a partner is moved to a different group
export async function queueDiscountCodeDeletion({
- discountId,
- discountCodeId,
-}: {
- discountId?: string;
- discountCodeId?: string;
-}) {
+ code,
+ stripeConnectId,
+}: Payload) {
await queue.upsert({
parallelism: 10,
});
- // Delete a discount code
- if (discountCodeId) {
- return await queue.enqueueJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/discounts/delete-discount-code`,
- method: "POST",
- body: {
- discountCodeId,
- },
- });
- }
-
- // Delete all codes for a discount
- if (discountId) {
- let cursor: undefined | string = undefined;
-
- while (true) {
- const discountCodes = await prisma.discountCode.findMany({
- where: {
- discountId,
- },
- select: {
- id: true,
- },
- orderBy: {
- createdAt: "asc",
- },
- cursor: {
- id: cursor,
- },
- take: 100,
- });
+ const response = await queue.enqueueJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/discounts/delete-discount-code`,
+ method: "POST",
+ body: {
+ code,
+ stripeConnectId,
+ },
+ });
+}
- if (discountCodes.length === 0) {
- break;
- }
+export async function batchQueueDiscountCodeDeletion({
+ discountId,
+ stripeConnectId
+}: {
+ discountId: string,
+ stripeConnectId: string,
+}) {
+ let cursor: undefined | string = undefined;
- console.log("discountCodes", discountCodes);
+ while (true) {
+ const discountCodes = await prisma.discountCode.findMany({
+ where: {
+ discountId,
+ },
+ select: {
+ id: true,
+ },
+ orderBy: {
+ createdAt: "asc",
+ },
+ cursor: {
+ id: cursor,
+ },
+ take: 100,
+ });
- const response = await Promise.allSettled(
- discountCodes.map(({ id }) =>
- queue.enqueueJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/discounts/delete-discount-code`,
- method: "POST",
- body: {
- discountCodeId: id,
- },
- }),
- ),
- );
+ if (discountCodes.length === 0) {
+ break;
+ }
- console.log("response", response);
+ await Promise.allSettled(
+ discountCodes.map(({ id }) =>
+ queue.enqueueJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/discounts/delete-discount-code`,
+ method: "POST",
+ body: {
+
+ },
+ }),
+ ),
+ );
- cursor = discountCodes[discountCodes.length - 1].id;
- }
+ cursor = discountCodes[discountCodes.length - 1].id;
}
}