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.

improve getProgramOrThrow

Steven Teyb3bbe1306e04
diff --git a/apps/web/app/api/programs/[programId]/route.ts b/apps/web/app/api/programs/[programId]/route.ts
index c7424579e5..11409501ed 100644
--- a/apps/web/app/api/programs/[programId]/route.ts
+++ b/apps/web/app/api/programs/[programId]/route.ts
@@ -4,10 +4,15 @@ import { NextResponse } from "next/server";
// GET /api/programs/[programId] - get a program by id
export const GET = withWorkspace(async ({ workspace, params }) => {
- const program = await getProgramOrThrow({
- workspaceId: workspace.id,
- programId: params.programId,
- });
+ const program = await getProgramOrThrow(
+ {
+ workspaceId: workspace.id,
+ programId: params.programId,
+ },
+ {
+ includeDiscounts: true,
+ },
+ );
return NextResponse.json(program);
});
diff --git a/apps/web/lib/api/programs/get-program-or-throw.ts b/apps/web/lib/api/programs/get-program-or-throw.ts
index d8d6b132a6..6d8f0209a0 100644
--- a/apps/web/lib/api/programs/get-program-or-throw.ts
+++ b/apps/web/lib/api/programs/get-program-or-throw.ts
@@ -2,21 +2,26 @@ import { ProgramSchema } from "@/lib/zod/schemas/programs";
import { prisma } from "@dub/prisma";
import { DubApiError } from "../errors";
-export const getProgramOrThrow = async ({
- workspaceId,
- programId,
-}: {
- workspaceId: string;
- programId: string;
-}) => {
+export const getProgramOrThrow = async (
+ {
+ workspaceId,
+ programId,
+ }: {
+ workspaceId: string;
+ programId: string;
+ },
+ {
+ includeDiscounts = false,
+ }: {
+ includeDiscounts?: boolean;
+ } = {},
+) => {
const program = await prisma.program.findUnique({
where: {
id: programId,
workspaceId,
},
- include: {
- discounts: true,
- },
+ ...(includeDiscounts ? { include: { discounts: true } } : {}),
});
if (!program) {