The modern link attribution platform. Loved by world-class engineering teams at Twilio, Zillow, Jobber, Vercel, Raycast, and more.
TypeScript clickhousemysqlnextjsopen-sourceplanetscaleprismatailwindcsstinybirdtypescriptupstashvercel
add typeAmountFilter
Steven Teyab1e423c2c6f
diff --git a/apps/web/app/api/cron/payouts/create-payout.ts b/apps/web/app/api/cron/payouts/create-payout.tsindex 64334ca3a6..a0530df0bc 100644--- a/apps/web/app/api/cron/payouts/create-payout.ts+++ b/apps/web/app/api/cron/payouts/create-payout.ts@@ -1,3 +1,4 @@+import { typeAmountFilter } from "@/lib/api/commissions/type-amount-filter";import { createId } from "@/lib/api/create-id";import { prisma } from "@dub/prisma";import { EventType, Payout } from "@dub/prisma/client";@@ -53,10 +54,10 @@ export const createPayout = async ({await prisma.$transaction(async (tx) => {const commissions = await tx.commission.findMany({where: {+ ...typeAmountFilter(type),programId,partnerId,payoutId: null,- type,status: "pending",// Only process commissions that were created before the holding period...(holdingPeriodDays > 0 && {diff --git a/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts b/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.tsindex a81b5de9d0..4ebb225d7c 100644--- a/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts+++ b/apps/web/app/api/partner-profile/programs/[programId]/earnings/route.ts@@ -1,4 +1,5 @@import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";+import { typeAmountFilter } from "@/lib/api/commissions/type-amount-filter";import { getProgramEnrollmentOrThrow } from "@/lib/api/programs/get-program-enrollment-or-throw";import { withPartnerProfile } from "@/lib/auth/partner";import { generateRandomName } from "@/lib/names";@@ -41,30 +42,7 @@ export const GET = withPartnerProfile(const earnings = await prisma.commission.findMany({where: {- ...(type- ? {- type,- ...(type === "sale" && {- amount: {- gt: 0,- },- }),- }- : {- OR: [- {- type: "sale",- amount: {- gt: 0,- },- },- {- type: {- not: "sale",- },- },- ],- }),+ ...typeAmountFilter(type),programId: program.id,partnerId: partner.id,status,diff --git a/apps/web/lib/api/commissions/type-amount-filter.ts b/apps/web/lib/api/commissions/type-amount-filter.tsnew file mode 100644index 0000000000..113b29f3cf--- /dev/null+++ b/apps/web/lib/api/commissions/type-amount-filter.ts@@ -0,0 +1,33 @@+import { Prisma } from "@dub/prisma/client";+import { EventType } from "@prisma/client";++export const typeAmountFilter = (+ type?: EventType,+): Prisma.CommissionWhereInput => {+ return {+ ...(type+ ? {+ type,+ ...(type === "sale" && {+ amount: {+ gt: 0,+ },+ }),+ }+ : {+ OR: [+ {+ type: "sale",+ amount: {+ gt: 0,+ },+ },+ {+ type: {+ not: "sale",+ },+ },+ ],+ }),+ };+};