Skip to content

Commit 125f8a5

Browse files
committed
fix useCustomersCount, update scripts
1 parent ec7de7e commit 125f8a5

3 files changed

Lines changed: 96 additions & 2 deletions

File tree

apps/web/lib/swr/use-customers-count.ts

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { useRouterStuff } from "@dub/ui";
12
import { fetcher } from "@dub/utils";
23
import useSWR from "swr";
3-
import { z } from "zod";
4+
import z from "../zod";
45
import { getCustomersCountQuerySchema } from "../zod/schemas/customers";
56
import useWorkspace from "./use-workspace";
67

@@ -12,14 +13,25 @@ export default function useCustomersCount<T = number>({
1213
enabled?: boolean;
1314
} = {}) {
1415
const { id: workspaceId } = useWorkspace();
16+
const { getQueryString } = useRouterStuff();
1517

1618
const { data, error } = useSWR<T>(
1719
enabled &&
1820
workspaceId &&
19-
`/api/customers/count?${new URLSearchParams({ workspaceId, ...query })}`,
21+
`/api/customers/count${getQueryString(
22+
{ workspaceId, ...query },
23+
{
24+
include: ["linkId", "country", "search"],
25+
},
26+
)}`,
2027
fetcher,
28+
{
29+
keepPreviousData: true,
30+
},
2131
);
2232

33+
console.log({ data });
34+
2335
return {
2436
data,
2537
error,
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { prisma } from "@dub/prisma";
2+
import "dotenv-flow/config";
3+
4+
let eventIds: string[] = [];
5+
6+
async function main() {
7+
const payouts = await prisma.payout.findMany({
8+
where: {
9+
programId: "prog_xxx",
10+
status: "pending",
11+
},
12+
});
13+
14+
const commissions = await prisma.commission.groupBy({
15+
by: ["payoutId"],
16+
where: {
17+
payoutId: { in: payouts.map((payout) => payout.id) },
18+
},
19+
_sum: {
20+
earnings: true,
21+
},
22+
});
23+
24+
// go through each to make sure total === amount, and log each
25+
for (const payout of payouts) {
26+
const total =
27+
commissions.find((commission) => commission.payoutId === payout.id)?._sum
28+
.earnings ?? 0;
29+
30+
if (total !== payout.amount) {
31+
console.log(
32+
`ALERT: Payout ${payout.id} has a total of ${total} but an amount of ${payout.amount}`,
33+
);
34+
} else {
35+
console.log(
36+
`Payout ${payout.id} matches ${total}, ${payout.amount}. skipping...`,
37+
);
38+
}
39+
}
40+
}
41+
42+
main();
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { prisma } from "@dub/prisma";
2+
import "dotenv-flow/config";
3+
import * as fs from "fs";
4+
import * as Papa from "papaparse";
5+
6+
let eventIds: string[] = [];
7+
8+
async function main() {
9+
Papa.parse(fs.createReadStream("framer_pending_event_ids.csv", "utf-8"), {
10+
header: true,
11+
skipEmptyLines: true,
12+
step: (result: { data: { event_id: string } }) => {
13+
eventIds.push(result.data.event_id);
14+
},
15+
complete: async () => {
16+
const commissionsToUpdate = await prisma.commission.findMany({
17+
where: {
18+
eventId: { in: eventIds },
19+
status: {
20+
not: "pending",
21+
},
22+
},
23+
take: 500,
24+
});
25+
26+
const updateCommissions = await prisma.commission.updateMany({
27+
where: {
28+
id: { in: commissionsToUpdate.map((commission) => commission.id) },
29+
},
30+
data: {
31+
status: "pending",
32+
},
33+
});
34+
35+
console.log(`Updated ${updateCommissions.count} commissions`);
36+
},
37+
});
38+
}
39+
40+
main();

0 commit comments

Comments
 (0)