Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion apps/web/app/(ee)/api/commissions/route.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -14,12 +15,13 @@ import { z } from "zod";
export const GET = withWorkspace(async ({ workspace, searchParams }) => {
const programId = getDefaultProgramIdOrThrow(workspace);

const {
let {
status,
type,
customerId,
payoutId,
partnerId,
tenantId,
invoiceId,
groupId,
page,
Expand All @@ -37,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
? {
Expand Down
10 changes: 9 additions & 1 deletion apps/web/lib/zod/schemas/commissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,15 @@ 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's `tenantId` (their unique ID within your database).",
),
groupId: z
.string()
.optional()
Expand Down