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.

Merge branch 'main' into link-based-coupon-codes

Kiran K6c1a7aaf16fb
diff --cc apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts
index 97290dc985,c92d7aa9db..7d66fdc4d5
--- a/apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts
+++ b/apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts
@@@ -319,51 -289,46 +324,54 @@@ export const DELETE = withWorkspace
});
}
- // 5. Delete the group
- // 4. Delete the group
++ // 45. Delete the group
await tx.partnerGroup.delete({
where: {
id: group.id,
},
});
+
+ return true;
});
+ const partnerIds = group.partners.map(({ partnerId }) => partnerId);
+
- waitUntil(
- Promise.allSettled([
- partnerIds.length > 0 &&
- qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/groups/remap-default-links`,
- body: {
- programId,
- groupId: defaultGroup.id,
- partnerIds,
- userId: session.user.id,
- isGroupDeleted: true,
- },
- }),
+ if (deletedGroup) {
+ waitUntil(
+ Promise.allSettled([
- qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/groups/remap-default-links`,
- body: {
- programId,
- groupId: defaultGroup.id,
- partnerIds: group.partners.map(({ partnerId }) => partnerId),
- userId: session.user.id,
- isGroupDeleted: true,
- },
- }),
++ partnerIds.length > 0 &&
++ qstash.publishJSON({
++ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/groups/remap-default-links`,
++ body: {
++ programId,
++ groupId: defaultGroup.id,
++ partnerIds,
++ userId: session.user.id,
++ isGroupDeleted: true,
++ },
++ }),
- recordAuditLog({
- workspaceId: workspace.id,
- programId,
- action: "group.deleted",
- description: `Group ${group.name} (${group.id}) deleted`,
- actor: session.user,
- targets: [
- {
- type: "group",
- id: group.id,
- metadata: group,
- },
- ],
- }),
- ]),
- );
+ ...discountCodesToDelete.map((discountCode) =>
+ queueDiscountCodeDeletion(discountCode.id),
+ ),
+
+ recordAuditLog({
+ workspaceId: workspace.id,
+ programId,
+ action: "group.deleted",
+ description: `Group ${group.name} (${group.id}) deleted`,
+ actor: session.user,
+ targets: [
+ {
+ type: "group",
+ id: group.id,
+ metadata: group,
+ },
+ ],
+ }),
+ ]),
+ );
+ }
return NextResponse.json({ id: group.id });
},
diff --cc apps/web/lib/actions/partners/update-discount.ts
index 4022127422,1ebd31967f..6dbef26135
--- a/apps/web/lib/actions/partners/update-discount.ts
+++ b/apps/web/lib/actions/partners/update-discount.ts
@@@ -5,9 -5,11 +5,11 @@@ import { getDiscountOrThrow } from "@/l
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { qstash } from "@/lib/cron";
import { updateDiscountSchema } from "@/lib/zod/schemas/discount";
+ import { DEFAULT_PARTNER_GROUP } from "@/lib/zod/schemas/groups";
import { prisma } from "@dub/prisma";
-import { APP_DOMAIN_WITH_NGROK, deepEqual } from "@dub/utils";
+import { APP_DOMAIN_WITH_NGROK } from "@dub/utils";
import { waitUntil } from "@vercel/functions";
+ import { revalidatePath } from "next/cache";
import { authActionClient } from "../safe-action";
export const updateDiscountAction = authActionClient
@@@ -23,50 -26,74 +25,60 @@@
discountId,
});
- const { partnerGroup, ...updatedDiscount } = await prisma.discount.update({
- where: {
- id: discountId,
- },
- data: {
- couponTestId: couponTestId || null,
- },
- include: {
- partnerGroup: {
- select: {
- id: true,
- },
+ const { program, partnerGroup, ...updatedDiscount } =
+ await prisma.discount.update({
+ where: {
+ id: discountId,
},
- },
- });
-
- const shouldExpireCache =
- discount.couponTestId !== updatedDiscount.couponTestId;
+ data: {
- amount,
- type,
- maxDuration,
- couponId,
- couponTestId,
++ couponTestId: couponTestId || null,
+ },
+ include: {
+ program: true,
+ partnerGroup: true,
+ },
+ });
waitUntil(
- Promise.allSettled([
- shouldExpireCache &&
- partnerGroup &&
- qstash.publishJSON({
- url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/invalidate-for-discounts`,
- body: {
- groupId: partnerGroup.id,
- },
- }),
+ (async () => {
- const shouldExpireCache = !deepEqual(
- {
- amount: discount.amount,
- type: discount.type,
- maxDuration: discount.maxDuration,
- },
- {
- amount: updatedDiscount.amount,
- type: updatedDiscount.type,
- maxDuration: updatedDiscount.maxDuration,
- },
- );
++ const shouldExpireCache =
++ discount.couponTestId !== updatedDiscount.couponTestId;
+
+ await Promise.allSettled([
+ ...(shouldExpireCache
+ ? [
+ qstash.publishJSON({
+ url: `${APP_DOMAIN_WITH_NGROK}/api/cron/links/invalidate-for-discounts`,
+ body: {
+ groupId: partnerGroup?.id,
+ },
+ }),
- recordAuditLog({
- workspaceId: workspace.id,
- programId,
- action: "discount.updated",
- description: `Discount ${discount.id} updated`,
- actor: user,
- targets: [
- {
- type: "discount",
- id: discount.id,
- metadata: updatedDiscount,
- },
- ],
- }),
- ]),
+ // we only cache default group pages for now so we need to invalidate them
+ ...(partnerGroup?.slug === DEFAULT_PARTNER_GROUP.slug
+ ? [
+ revalidatePath(`/partners.dub.co/${program.slug}`),
+ revalidatePath(`/partners.dub.co/${program.slug}/apply`),
+ ]
+ : []),
+ ]
+ : []),
+
+ recordAuditLog({
+ workspaceId: workspace.id,
+ programId,
+ action: "discount.updated",
+ description: `Discount ${discount.id} updated`,
+ actor: user,
+ targets: [
+ {
+ type: "discount",
+ id: discount.id,
+ metadata: updatedDiscount,
+ },
+ ],
+ }),
+ ]);
+ })(),
);
});
diff --cc packages/prisma/schema/program.prisma
index ce8c8feb6e,f9410f86a1..4651a271c3
--- a/packages/prisma/schema/program.prisma
+++ b/packages/prisma/schema/program.prisma
@@@ -42,9 -42,9 +42,9 @@@ model Program
holdingPeriodDays Int @default(0) // number of days to wait before earnings are added to a payout
minPayoutAmount Int @default(0) // Default minimum payout amount of $0
embedData Json? @db.Json
- landerData Json? @db.Json
- landerPublishedAt DateTime?
- applicationFormData Json? @db.Json
+ landerData Json? @db.Json // TODO: drop this column after PR #2893 merges
- landerPublishedAt DateTime? // TODO: drop this column after PR #2893 merges
++ landerPublishedAt DateTime? // TODO: drop this column after PR #2893 merges
+ applicationFormData Json? @db.Json // TODO: drop this column after PR #2893 merges
resources Json? @db.Json
termsUrl String? @db.Text
helpUrl String? @db.Text
@@@ -72,7 -72,7 +72,8 @@@
workflows Workflow[]
messages Message[]
comments PartnerComment[]
+ discountCodes DiscountCode[]
+ campaigns Campaign[]
@@index(workspaceId)
@@index(domain)