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.

endOfMonth

Steven Tey97767c3e7d4b
diff --git a/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts b/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
index 207eb0e050..b4d6726daa 100644
--- a/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/confirm/split-payouts.ts
@@ -1,6 +1,7 @@
import { createId } from "@/lib/api/create-id";
import { prisma } from "@dub/prisma";
import { Program } from "@prisma/client";
+import { endOfMonth } from "date-fns";
export async function splitPayouts({
program,
@@ -62,17 +63,13 @@ export async function splitPayouts({
// 1 - one for everything up until the end of the previous month
// 2 - everything else in the current month will be left as pending (and excluded from the payout)
if (previousCommissionsCount > 0) {
- const periodEnd =
- previousCommissions[previousCommissionsCount - 1].createdAt;
-
await prisma.payout.update({
where: {
id: payout.id,
},
data: {
- periodEnd: new Date(
- periodEnd.getFullYear(),
- periodEnd.getMonth() + 1,
+ periodEnd: endOfMonth(
+ previousCommissions[previousCommissionsCount - 1].createdAt,
),
amount: previousCommissions.reduce(
(total, commission) => total + commission.earnings,
@@ -82,18 +79,14 @@ export async function splitPayouts({
});
if (currentCommissionsCount > 0) {
- const periodEnd =
- currentCommissions[currentCommissions.length - 1].createdAt;
-
const currentMonthPayout = await prisma.payout.create({
data: {
id: createId({ prefix: "po_" }),
programId: program.id,
partnerId: payout.partnerId,
periodStart: currentCommissions[0].createdAt,
- periodEnd: new Date(
- periodEnd.getFullYear(),
- periodEnd.getMonth() + 1,
+ periodEnd: endOfMonth(
+ currentCommissions[currentCommissions.length - 1].createdAt,
),
amount: currentCommissions.reduce(
(total, commission) => total + commission.earnings,
diff --git a/apps/web/app/(ee)/api/cron/payouts/create-payout.ts b/apps/web/app/(ee)/api/cron/payouts/create-payout.ts
index 1d7f18fcf1..c8a9ab6111 100644
--- a/apps/web/app/(ee)/api/cron/payouts/create-payout.ts
+++ b/apps/web/app/(ee)/api/cron/payouts/create-payout.ts
@@ -1,5 +1,6 @@
import { createId } from "@/lib/api/create-id";
import { prisma } from "@dub/prisma";
+import { endOfMonth } from "date-fns";
export const createPayout = async ({
programId,
@@ -93,8 +94,7 @@ export const createPayout = async ({
// end of the month of the latest commission date
// e.g. if the latest sale is 2024-12-16, the periodEnd should be 2024-12-31
- let periodEnd = commissions[commissions.length - 1].createdAt;
- periodEnd = new Date(periodEnd.getFullYear(), periodEnd.getMonth() + 1);
+ const periodEnd = endOfMonth(commissions[commissions.length - 1].createdAt);
await prisma.$transaction(async (tx) => {
// check if the partner has another pending payout (take the latest entry)
diff --git a/apps/web/tests/commissions/index.test.ts b/apps/web/tests/commissions/index.test.ts
index 54d3f9bf31..9f61f107fe 100644
--- a/apps/web/tests/commissions/index.test.ts
+++ b/apps/web/tests/commissions/index.test.ts
@@ -29,8 +29,6 @@ describe.sequential("/commissions/**", async () => {
path: "/commissions",
query: {
status: "processed",
- page: "1",
- pageSize: "10",
sortBy: "createdAt",
sortOrder: "desc",
},
diff --git a/packages/email/src/templates/partner-payout-confirmed.tsx b/packages/email/src/templates/partner-payout-confirmed.tsx
index 50e32378e5..3b9e507240 100644
--- a/packages/email/src/templates/partner-payout-confirmed.tsx
+++ b/packages/email/src/templates/partner-payout-confirmed.tsx
@@ -52,6 +52,7 @@ export default function PartnerPayoutConfirmed({
year: "numeric",
month: "short",
day: "numeric",
+ timeZone: "UTC",
})
: null;
@@ -60,6 +61,7 @@ export default function PartnerPayoutConfirmed({
year: "numeric",
month: "short",
day: "numeric",
+ timeZone: "UTC",
})
: null;
diff --git a/packages/email/src/templates/partner-payout-sent.tsx b/packages/email/src/templates/partner-payout-sent.tsx
index 5b5162844e..53d239c21b 100644
--- a/packages/email/src/templates/partner-payout-sent.tsx
+++ b/packages/email/src/templates/partner-payout-sent.tsx
@@ -51,6 +51,7 @@ export function PartnerPayoutSent({
year: "numeric",
month: "short",
day: "numeric",
+ timeZone: "UTC",
})
: null;
@@ -59,6 +60,7 @@ export function PartnerPayoutSent({
year: "numeric",
month: "short",
day: "numeric",
+ timeZone: "UTC",
})
: null;