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.

backfill invoice paidAt

Steven Tey294ea4aff961
diff --git a/apps/web/app/admin.dub.co/(dashboard)/layout.tsx b/apps/web/app/admin.dub.co/(dashboard)/layout.tsx
index d77bfbe051..31c4bdbea2 100644
--- a/apps/web/app/admin.dub.co/(dashboard)/layout.tsx
+++ b/apps/web/app/admin.dub.co/(dashboard)/layout.tsx
@@ -15,8 +15,8 @@ const tabs = [
label: "Analytics",
},
{
- href: "/revenue",
- label: "Revenue",
+ href: "/payouts",
+ label: "Payouts",
},
{
href: "/demo",
diff --git a/apps/web/app/admin.dub.co/(dashboard)/revenue/client.tsx b/apps/web/app/admin.dub.co/(dashboard)/payouts/client.tsx
similarity index 98%
rename from apps/web/app/admin.dub.co/(dashboard)/revenue/client.tsx
rename to apps/web/app/admin.dub.co/(dashboard)/payouts/client.tsx
index 35bed7cbf1..27b2c8441a 100644
--- a/apps/web/app/admin.dub.co/(dashboard)/revenue/client.tsx
+++ b/apps/web/app/admin.dub.co/(dashboard)/payouts/client.tsx
@@ -4,7 +4,7 @@ import { Areas, TimeSeriesChart, XAxis, YAxis } from "@dub/ui/charts";
import { nFormatter } from "@dub/utils";
import { Fragment } from "react";
-export default function RevenueClient({
+export default function PayoutsPageClient({
data,
}: {
data: { date: Date; value: number }[];
diff --git a/apps/web/app/admin.dub.co/(dashboard)/payouts/page.tsx b/apps/web/app/admin.dub.co/(dashboard)/payouts/page.tsx
new file mode 100644
index 0000000000..f142434562
--- /dev/null
+++ b/apps/web/app/admin.dub.co/(dashboard)/payouts/page.tsx
@@ -0,0 +1,33 @@
+import LayoutLoader from "@/ui/layout/layout-loader";
+import { prisma } from "@dub/prisma";
+import { ACME_WORKSPACE_ID } from "@dub/utils";
+import { Suspense } from "react";
+export const dynamic = "force-dynamic";
+
+export default function PayoutsPage() {
+ return (
+ <Suspense fallback={<LayoutLoader />}>
+ <PayoutsRSC />
+ </Suspense>
+ );
+}
+
+async function PayoutsRSC() {
+ const invoices = await prisma.invoice.findMany({
+ where: {
+ workspaceId: {
+ not: ACME_WORKSPACE_ID,
+ },
+ paidAt: {
+ not: null,
+ },
+ },
+ });
+
+ return (
+ <div>
+ <h1>Payouts</h1>
+ <pre>{JSON.stringify(invoices, null, 2)}</pre>
+ </div>
+ );
+}
diff --git a/apps/web/app/admin.dub.co/(dashboard)/revenue/page.tsx b/apps/web/app/admin.dub.co/(dashboard)/revenue/page.tsx
deleted file mode 100644
index 6c18eef7c0..0000000000
--- a/apps/web/app/admin.dub.co/(dashboard)/revenue/page.tsx
+++ /dev/null
@@ -1,72 +0,0 @@
-import LayoutLoader from "@/ui/layout/layout-loader";
-import { Suspense } from "react";
-import RevenueClient from "./client";
-
-export const dynamic = "force-dynamic";
-
-export default function Revenue() {
- return (
- <Suspense fallback={<LayoutLoader />}>
- <RevenueRSC />
- </Suspense>
- );
-}
-
-async function RevenueRSC() {
- const data = [
- {
- date: new Date("2024-03-01"),
- value: 123050,
- },
- {
- date: new Date("2024-04-01"),
- value: 223050,
- },
- {
- date: new Date("2024-05-01"),
- value: 323050,
- },
- {
- date: new Date("2024-06-01"),
- value: 423050,
- },
- {
- date: new Date("2024-07-01"),
- value: 523050,
- },
- {
- date: new Date("2024-08-01"),
- value: 623050,
- },
- {
- date: new Date("2024-09-01"),
- value: 723050,
- },
- {
- date: new Date("2024-10-01"),
- value: 823050,
- },
- {
- date: new Date("2024-11-01"),
- value: 923050,
- },
- {
- date: new Date("2024-12-01"),
- value: 723050,
- },
- {
- date: new Date("2025-01-01"),
- value: 823050,
- },
- {
- date: new Date("2025-02-01"),
- value: 1032920,
- },
- {
- date: new Date("2025-03-01"),
- value: 33013039,
- },
- ];
-
- return <RevenueClient data={data} />;
-}
diff --git a/apps/web/scripts/backfill-invoice-paid-at.ts b/apps/web/scripts/backfill-invoice-paid-at.ts
new file mode 100644
index 0000000000..92cf472cd0
--- /dev/null
+++ b/apps/web/scripts/backfill-invoice-paid-at.ts
@@ -0,0 +1,32 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+
+async function main() {
+ const invoices = await prisma.invoice.findMany({
+ where: {
+ paidAt: null,
+ },
+ orderBy: {
+ createdAt: "asc",
+ },
+ include: {
+ payouts: {
+ take: 1,
+ },
+ },
+ });
+
+ for (const invoice of invoices) {
+ if (invoice.payouts.length > 0 && invoice.payouts[0].paidAt) {
+ await prisma.invoice.update({
+ where: { id: invoice.id },
+ data: { paidAt: invoice.payouts[0].paidAt },
+ });
+ console.log(
+ `Updated invoice ${invoice.id} to ${invoice.payouts[0].paidAt}`,
+ );
+ }
+ }
+}
+
+main();
diff --git a/packages/prisma/schema/invoice.prisma b/packages/prisma/schema/invoice.prisma
index c5f58fcceb..9f49641141 100644
--- a/packages/prisma/schema/invoice.prisma
+++ b/packages/prisma/schema/invoice.prisma
@@ -22,6 +22,6 @@ model Invoice {
program Program @relation(fields: [programId], references: [id])
workspace Project @relation(fields: [workspaceId], references: [id])
- @@index([programId])
- @@index([workspaceId])
+ @@index(programId)
+ @@index(workspaceId)
}