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.

fix useCustomersCount, update scripts

Steven Tey125f8a54c15f
diff --git a/apps/web/lib/swr/use-customers-count.ts b/apps/web/lib/swr/use-customers-count.ts
index d32b3c969f..07e4ba43db 100644
--- a/apps/web/lib/swr/use-customers-count.ts
+++ b/apps/web/lib/swr/use-customers-count.ts
@@ -1,6 +1,7 @@
+import { useRouterStuff } from "@dub/ui";
import { fetcher } from "@dub/utils";
import useSWR from "swr";
-import { z } from "zod";
+import z from "../zod";
import { getCustomersCountQuerySchema } from "../zod/schemas/customers";
import useWorkspace from "./use-workspace";
@@ -12,14 +13,25 @@ export default function useCustomersCount<T = number>({
enabled?: boolean;
} = {}) {
const { id: workspaceId } = useWorkspace();
+ const { getQueryString } = useRouterStuff();
const { data, error } = useSWR<T>(
enabled &&
workspaceId &&
- `/api/customers/count?${new URLSearchParams({ workspaceId, ...query })}`,
+ `/api/customers/count${getQueryString(
+ { workspaceId, ...query },
+ {
+ include: ["linkId", "country", "search"],
+ },
+ )}`,
fetcher,
+ {
+ keepPreviousData: true,
+ },
);
+ console.log({ data });
+
return {
data,
error,
diff --git a/apps/web/scripts/framer/check-pending-payout-totals.ts b/apps/web/scripts/framer/check-pending-payout-totals.ts
new file mode 100644
index 0000000000..20466dd8c5
--- /dev/null
+++ b/apps/web/scripts/framer/check-pending-payout-totals.ts
@@ -0,0 +1,42 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+
+let eventIds: string[] = [];
+
+async function main() {
+ const payouts = await prisma.payout.findMany({
+ where: {
+ programId: "prog_xxx",
+ status: "pending",
+ },
+ });
+
+ const commissions = await prisma.commission.groupBy({
+ by: ["payoutId"],
+ where: {
+ payoutId: { in: payouts.map((payout) => payout.id) },
+ },
+ _sum: {
+ earnings: true,
+ },
+ });
+
+ // go through each to make sure total === amount, and log each
+ for (const payout of payouts) {
+ const total =
+ commissions.find((commission) => commission.payoutId === payout.id)?._sum
+ .earnings ?? 0;
+
+ if (total !== payout.amount) {
+ console.log(
+ `ALERT: Payout ${payout.id} has a total of ${total} but an amount of ${payout.amount}`,
+ );
+ } else {
+ console.log(
+ `Payout ${payout.id} matches ${total}, ${payout.amount}. skipping...`,
+ );
+ }
+ }
+}
+
+main();
diff --git a/apps/web/scripts/framer/mark-commissions-pending.ts b/apps/web/scripts/framer/mark-commissions-pending.ts
new file mode 100644
index 0000000000..daae01e6ab
--- /dev/null
+++ b/apps/web/scripts/framer/mark-commissions-pending.ts
@@ -0,0 +1,40 @@
+import { prisma } from "@dub/prisma";
+import "dotenv-flow/config";
+import * as fs from "fs";
+import * as Papa from "papaparse";
+
+let eventIds: string[] = [];
+
+async function main() {
+ Papa.parse(fs.createReadStream("framer_pending_event_ids.csv", "utf-8"), {
+ header: true,
+ skipEmptyLines: true,
+ step: (result: { data: { event_id: string } }) => {
+ eventIds.push(result.data.event_id);
+ },
+ complete: async () => {
+ const commissionsToUpdate = await prisma.commission.findMany({
+ where: {
+ eventId: { in: eventIds },
+ status: {
+ not: "pending",
+ },
+ },
+ take: 500,
+ });
+
+ const updateCommissions = await prisma.commission.updateMany({
+ where: {
+ id: { in: commissionsToUpdate.map((commission) => commission.id) },
+ },
+ data: {
+ status: "pending",
+ },
+ });
+
+ console.log(`Updated ${updateCommissions.count} commissions`);
+ },
+ });
+}
+
+main();