Skip to content

Commit fd62570

Browse files
committed
small updates
1 parent cb8d9ea commit fd62570

3 files changed

Lines changed: 59 additions & 0 deletions

File tree

apps/web/app/partners.dub.co/(dashboard)/settings/payouts/payout-details-sheet.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ function PayoutDetailsSheetContent({
193193
<div className="mt-2 flex justify-end">
194194
<Link
195195
href={`/programs/${payout.program.slug}/sales`}
196+
target="_blank"
196197
className={cn(
197198
buttonVariants({ variant: "secondary" }),
198199
"flex h-7 items-center rounded-lg border px-2 text-sm",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import { calculateSaleEarnings } from "@/lib/api/sales/calculate-sale-earnings";
2+
import { prisma } from "@dub/prisma";
3+
import { Prisma } from "@dub/prisma/client";
4+
import "dotenv-flow/config";
5+
6+
// update commissions for a program
7+
async function main() {
8+
const where: Prisma.CommissionWhereInput = {
9+
earnings: 0,
10+
programId: "prog_xxx",
11+
};
12+
13+
const commissions = await prisma.commission.findMany({
14+
where,
15+
take: 100,
16+
});
17+
18+
const reward = await prisma.reward.findUniqueOrThrow({
19+
where: {
20+
id: "rw_xxx",
21+
},
22+
});
23+
24+
const updatedCommissions = await Promise.all(
25+
commissions.map(async (commission) => {
26+
// Recalculate the earnings based on the new amount
27+
const earnings = calculateSaleEarnings({
28+
reward,
29+
sale: {
30+
amount: commission.amount,
31+
quantity: commission.quantity,
32+
},
33+
});
34+
35+
return prisma.commission.update({
36+
where: { id: commission.id },
37+
data: {
38+
earnings,
39+
},
40+
});
41+
}),
42+
);
43+
console.table(updatedCommissions, [
44+
"id",
45+
"partnerId",
46+
"amount",
47+
"earnings",
48+
"createdAt",
49+
]);
50+
51+
const remainingCommissions = await prisma.commission.count({
52+
where,
53+
});
54+
console.log(`${remainingCommissions} commissions left to update`);
55+
}
56+
57+
main();

apps/web/ui/partners/payout-details-sheet.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ function PayoutDetailsSheetContent({
203203
<div className="mt-2 flex justify-end">
204204
<Link
205205
href={`/${slug}/programs/${programId}/sales?payoutId=${payout.id}&interval=all`}
206+
target="_blank"
206207
className={cn(
207208
buttonVariants({ variant: "secondary" }),
208209
"flex h-7 items-center rounded-lg border px-2 text-sm",

0 commit comments

Comments
 (0)