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 create-discount.ts

Kiran K1cfa644a932e
diff --git a/apps/web/lib/actions/partners/create-discount.ts b/apps/web/lib/actions/partners/create-discount.ts
index 543b49b5c2..09538853bc 100644
--- a/apps/web/lib/actions/partners/create-discount.ts
+++ b/apps/web/lib/actions/partners/create-discount.ts
@@ -34,7 +34,7 @@ export const createDiscountAction = authActionClient
const programId = getDefaultProgramIdOrThrow(workspace);
- await getProgramOrThrow({
+ const program = await getProgramOrThrow({
workspaceId: workspace.id,
programId,
});
@@ -174,12 +174,26 @@ export const createDiscountAction = authActionClient
}),
// If the coupon code is created on Stripe, create a promotion code for each link
- stripeCoupon ? qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/create-promotion-codes`,
- body: {
- discountId: discount.id,
- },
- }) : Promise.resolve(),
+ stripeCoupon
+ ? qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/create-promotion-codes`,
+ body: {
+ discountId: discount.id,
+ },
+ })
+ : Promise.resolve(),
+
+ // Enable the coupon-code tracking if not already enabled
+ stripeCoupon && !program.couponCodeTrackingEnabledAt
+ ? prisma.program.update({
+ where: {
+ id: programId,
+ },
+ data: {
+ couponCodeTrackingEnabledAt: new Date(),
+ },
+ })
+ : Promise.resolve(),
]);
})(),
);