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.

Merge branch 'partners' into payouts

Kiran Kdccebdf72233
diff --cc apps/web/app/api/programs/route.ts
index 5eeee4296a,3ffe945347..46efa4ace1
--- a/apps/web/app/api/programs/route.ts
+++ b/apps/web/app/api/programs/route.ts
@@@ -1,47 -1,20 +1,20 @@@
- import { DubApiError } from "@/lib/api/errors";
- import { createId, parseRequestBody } from "@/lib/api/utils";
- import { withWorkspace } from "@/lib/auth";
+ import { withPartner } from "@/lib/auth/partner";
import { prisma } from "@/lib/prisma";
- import { createProgramSchema, programSchema } from "@/lib/zod/schemas/programs";
+ import { ProgramSchema } from "@/lib/zod/schemas/partners";
import { NextResponse } from "next/server";
+import { z } from "zod";
- // GET /api/programs - get all programs for the given workspace
- export const GET = withWorkspace(async ({ workspace }) => {
+ // GET /api/programs - get all partner programs for a given partnerId or workspaceId
+ export const GET = withPartner(async ({ partner }) => {
const programs = await prisma.program.findMany({
where: {
- workspaceId: workspace.id,
+ partners: {
+ some: {
+ partnerId: partner.id,
+ },
+ },
},
});
- return NextResponse.json(
- programs.map((program) => ProgramSchema.parse(program)),
- );
+
- return NextResponse.json(z.array(programSchema).parse(programs));
- });
-
- // POST /api/programs/ - create a new programs
- export const POST = withWorkspace(async ({ req, workspace }) => {
- const { name, slug } = createProgramSchema.parse(await parseRequestBody(req));
-
- const existingProgram = await prisma.program.findFirst({
- where: {
- slug,
- },
- });
-
- if (existingProgram) {
- throw new DubApiError({
- code: "conflict",
- message: "A program with this slug already exists.",
- });
- }
-
- const program = await prisma.program.create({
- data: {
- id: createId("pg"),
- workspaceId: workspace.id,
- name,
- slug,
- },
- });
-
- return NextResponse.json(programSchema.parse(program), { status: 201 });
++ return NextResponse.json(z.array(ProgramSchema).parse(programs));
});