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.

small fixes

Steven Teye2234e89e588
diff --git a/apps/web/scripts/testimonial/final-sync-commissions.ts b/apps/web/scripts/testimonial/final-sync-commissions.ts
new file mode 100644
index 0000000000..1c3731a9b0
--- /dev/null
+++ b/apps/web/scripts/testimonial/final-sync-commissions.ts
@@ -0,0 +1,69 @@
+import { prisma } from "@dub/prisma";
+import { Prisma } from "@dub/prisma/client";
+import "dotenv-flow/config";
+
+// update commissions for a program
+async function main() {
+ const where: Prisma.CommissionWhereInput = {
+ programId: "prog_xxx",
+ payoutId: {
+ not: null,
+ },
+ status: "processed",
+ };
+
+ const payoutsStats = await prisma.commission.groupBy({
+ by: ["payoutId"],
+ where,
+ _count: true,
+ _sum: {
+ earnings: true,
+ },
+ orderBy: {
+ _sum: {
+ earnings: "desc",
+ },
+ },
+ });
+ console.log(payoutsStats);
+
+ const actualPayouts = await prisma.payout.findMany({
+ where: {
+ id: {
+ in: payoutsStats.map((payout) => payout.payoutId!),
+ },
+ },
+ select: {
+ id: true,
+ quantity: true,
+ amount: true,
+ },
+ });
+
+ for (const payout of actualPayouts) {
+ const payoutStats = payoutsStats.find(
+ (payoutStat) => payoutStat.payoutId === payout.id,
+ );
+ if (!payoutStats) {
+ console.log(`Payout ${payout.id} not found in payoutsStats`);
+ continue;
+ }
+ if (
+ payoutStats._count !== payout.quantity ||
+ payoutStats._sum.earnings !== payout.amount
+ ) {
+ console.log(
+ `Payout ${payout.id} has a mismatch, updating payout and commissions`,
+ );
+ await prisma.payout.update({
+ where: { id: payout.id },
+ data: {
+ quantity: payoutStats._count,
+ amount: payoutStats._sum.earnings ?? 0,
+ },
+ });
+ }
+ }
+}
+
+main();
diff --git a/apps/web/scripts/testimonial/sync-commissions.ts b/apps/web/scripts/testimonial/sync-commissions.ts
new file mode 100644
index 0000000000..0b48bc2380
--- /dev/null
+++ b/apps/web/scripts/testimonial/sync-commissions.ts
@@ -0,0 +1,73 @@
+import { prisma } from "@dub/prisma";
+import { Prisma } from "@dub/prisma/client";
+import "dotenv-flow/config";
+
+// update commissions for a program
+async function main() {
+ const where: Prisma.CommissionWhereInput = {
+ programId: "prog_xxx",
+ payoutId: {
+ not: null,
+ },
+ status: "paid",
+ };
+
+ const payoutsToUpdate = await prisma.commission.groupBy({
+ by: ["payoutId"],
+ where,
+ _count: true,
+ orderBy: {
+ _count: {
+ payoutId: "desc",
+ },
+ },
+ });
+
+ for (const payout of payoutsToUpdate) {
+ if (!payout.payoutId) {
+ console.log(`No payout ID found for payout ${payout.payoutId}`);
+ continue;
+ }
+
+ await prisma.commission.updateMany({
+ where: {
+ payoutId: payout.payoutId,
+ status: "paid",
+ },
+ data: { payoutId: null },
+ });
+
+ const remainingCommissions = await prisma.commission.findMany({
+ where: {
+ payoutId: payout.payoutId,
+ },
+ });
+
+ console.log(
+ `Updated ${payout.payoutId} to have ${remainingCommissions.length} commissions`,
+ );
+
+ if (remainingCommissions.length === 0) {
+ console.log(
+ `No remaining commissions for payout ${payout.payoutId}, deleting payout`,
+ );
+ await prisma.payout.delete({
+ where: { id: payout.payoutId },
+ });
+ continue;
+ }
+
+ await prisma.payout.update({
+ where: { id: payout.payoutId },
+ data: {
+ quantity: remainingCommissions.length,
+ amount: remainingCommissions.reduce(
+ (acc, commission) => acc + commission.earnings,
+ 0,
+ ),
+ },
+ });
+ }
+}
+
+main();
diff --git a/apps/web/ui/modals/import-rewardful-modal.tsx b/apps/web/ui/modals/import-rewardful-modal.tsx
index aae4050aa4..5a80ffc3f3 100644
--- a/apps/web/ui/modals/import-rewardful-modal.tsx
+++ b/apps/web/ui/modals/import-rewardful-modal.tsx
@@ -310,9 +310,11 @@ function CampaignsStep({
</dd>
</div>
<div>
- <dt className="text-neutral-500">Commission Period</dt>
+ <dt className="text-neutral-500">Duration</dt>
<dd className="font-medium text-neutral-700">
- {selectedCampaign.max_commission_period_months} months
+ {selectedCampaign.max_commission_period_months
+ ? `${selectedCampaign.max_commission_period_months} months`
+ : "Lifetime"}
</dd>
</div>
<div>