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.

Script + tweak

Tim Wilson90091627f67e
diff --git a/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/rewind.tsx b/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/rewind.tsx
index fdcd2fae41..065f5044a1 100644
--- a/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/rewind.tsx
+++ b/apps/web/app/(ee)/partners.dub.co/(dashboard)/rewind/2025/rewind.tsx
@@ -58,7 +58,7 @@ export function Rewind({
const { ShareRewindModal, setShowShareRewindModal } = useShareRewindModal({
rewindId: partnerRewind.id,
- step: steps[currentStepIndex].id,
+ step: steps[Math.min(currentStepIndex, steps.length - 1)].id,
});
return (
diff --git a/apps/web/scripts/dub-partner-rewind.ts b/apps/web/scripts/dub-partner-rewind.ts
new file mode 100644
index 0000000000..3e1632e158
--- /dev/null
+++ b/apps/web/scripts/dub-partner-rewind.ts
@@ -0,0 +1,93 @@
+import { prisma } from "@dub/prisma";
+import { ACME_PROGRAM_ID } from "@dub/utils";
+import "dotenv-flow/config";
+
+const PAGE_SIZE = 100;
+
+async function main() {
+ const partners = await prisma.partner.findMany({
+ select: {
+ id: true,
+ programs: {
+ where: {
+ programId: {
+ not: ACME_PROGRAM_ID,
+ },
+ },
+ select: {
+ totalClicks: true,
+ totalLeads: true,
+ totalSaleAmount: true,
+ totalCommissions: true,
+ },
+ },
+ },
+ where: {
+ partnerRewinds: {
+ none: {
+ year: 2025,
+ },
+ },
+ programs: {
+ some: {
+ programId: {
+ not: ACME_PROGRAM_ID,
+ },
+ OR: [
+ {
+ totalClicks: {
+ gt: 0,
+ },
+ },
+ {
+ totalLeads: {
+ gt: 0,
+ },
+ },
+ {
+ totalSaleAmount: {
+ gt: 0,
+ },
+ },
+ {
+ totalCommissions: {
+ gt: 0,
+ },
+ },
+ ],
+ },
+ },
+ },
+ take: PAGE_SIZE,
+ });
+
+ const payloads = partners.map(({ id, programs }) => ({
+ partnerId: id,
+ year: 2025,
+ ...programs.reduce(
+ (
+ acc,
+ { totalClicks, totalLeads, totalSaleAmount, totalCommissions },
+ ) => ({
+ totalClicks: acc.totalClicks + totalClicks,
+ totalLeads: acc.totalLeads + totalLeads,
+ totalRevenue: acc.totalRevenue + totalSaleAmount,
+ totalEarnings: acc.totalEarnings + totalCommissions,
+ }),
+ {
+ totalClicks: 0,
+ totalLeads: 0,
+ totalRevenue: 0,
+ totalEarnings: 0,
+ },
+ ),
+ }));
+
+ console.table(payloads);
+
+ await prisma.partnerRewind.createMany({
+ data: payloads,
+ });
+}
+
+main();