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.

small tweaks

Steven Teyfe312ca8d993
diff --git a/apps/web/app/(ee)/api/commissions/route.ts b/apps/web/app/(ee)/api/commissions/route.ts
index cffcc2a151..0c5f485fba 100644
--- a/apps/web/app/(ee)/api/commissions/route.ts
+++ b/apps/web/app/(ee)/api/commissions/route.ts
@@ -1,5 +1,6 @@
import { getStartEndDates } from "@/lib/analytics/utils/get-start-end-dates";
import { transformCustomerForCommission } from "@/lib/api/customers/transform-customer";
+import { DubApiError } from "@/lib/api/errors";
import { getDefaultProgramIdOrThrow } from "@/lib/api/programs/get-default-program-id-or-throw";
import { withWorkspace } from "@/lib/auth";
import {
@@ -14,7 +15,7 @@ import { z } from "zod";
export const GET = withWorkspace(async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);
- const {
+ let {
status,
type,
customerId,
@@ -38,6 +39,27 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
end,
});
+ if (tenantId && !partnerId) {
+ const partner = await prisma.programEnrollment.findUnique({
+ where: {
+ tenantId_programId: {
+ tenantId,
+ programId,
+ },
+ },
+ select: {
+ partnerId: true,
+ },
+ });
+ if (!partner) {
+ throw new DubApiError({
+ code: "not_found",
+ message: `Partner with specified tenantId ${tenantId} not found.`,
+ });
+ }
+ partnerId = partner.partnerId;
+ }
+
const commissions = await prisma.commission.findMany({
where: invoiceId
? {
@@ -68,17 +90,6 @@ export const GET = withWorkspace(async ({ workspace, searchParams }) => {
},
},
}),
- ...(tenantId &&
- !partnerId && {
- partner: {
- programs: {
- some: {
- tenantId,
- programId,
- },
- },
- },
- }),
},
include: {
customer: true,
diff --git a/apps/web/lib/zod/schemas/commissions.ts b/apps/web/lib/zod/schemas/commissions.ts
index a2e3affe27..7500cf895d 100644
--- a/apps/web/lib/zod/schemas/commissions.ts
+++ b/apps/web/lib/zod/schemas/commissions.ts
@@ -63,12 +63,14 @@ export const getCommissionsQuerySchema = z
partnerId: z
.string()
.optional()
- .describe("Filter the list of commissions by the associated partner."),
+ .describe(
+ "Filter the list of commissions by the associated partner. When specified, takes precedence over `tenantId`.",
+ ),
tenantId: z
.string()
.optional()
.describe(
- "Filter the list of commissions by the associated partner tenantId.",
+ "Filter the list of commissions by the associated partner's `tenantId` (their unique ID within your database).",
),
groupId: z
.string()