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.

Refactor partner schemas and update API response handling

Kiran K3d7ca98b63e5
diff --git a/apps/web/app/(ee)/api/partners/route.ts b/apps/web/app/(ee)/api/partners/route.ts
index 705c7baa7f..4cf86b31fb 100644
--- a/apps/web/app/(ee)/api/partners/route.ts
+++ b/apps/web/app/(ee)/api/partners/route.ts
@@ -27,8 +27,8 @@ export const GET = withWorkspace(
});
const responseSchema = parsedParams.includeExpandedFields
- ? EnrolledPartnerSchema
- : EnrolledPartnerBasicSchema;
+ ? EnrolledPartnerBasicSchema
+ : EnrolledPartnerSchema;
return NextResponse.json(z.array(responseSchema).parse(partners));
},
diff --git a/apps/web/lib/openapi/partners/get-partners.ts b/apps/web/lib/openapi/partners/get-partners.ts
index efd95810f1..2782aa0aaa 100644
--- a/apps/web/lib/openapi/partners/get-partners.ts
+++ b/apps/web/lib/openapi/partners/get-partners.ts
@@ -1,7 +1,7 @@
import { openApiErrorResponses } from "@/lib/openapi/responses";
import z from "@/lib/zod";
import {
- EnrolledPartnerSchemaExtended,
+ EnrolledPartnerSchema,
partnersQuerySchema,
} from "@/lib/zod/schemas/partners";
import { ZodOpenApiOperationObject } from "zod-openapi";
@@ -19,7 +19,7 @@ export const getPartners: ZodOpenApiOperationObject = {
description: "The list of partners.",
content: {
"application/json": {
- schema: z.array(EnrolledPartnerSchemaExtended),
+ schema: z.array(EnrolledPartnerSchema),
},
},
},
diff --git a/apps/web/lib/zod/schemas/partners.ts b/apps/web/lib/zod/schemas/partners.ts
index 5ffc343206..5fe9930818 100644
--- a/apps/web/lib/zod/schemas/partners.ts
+++ b/apps/web/lib/zod/schemas/partners.ts
@@ -282,32 +282,39 @@ export const EnrolledPartnerBasicSchema = PartnerSchema.pick({
export const EnrolledPartnerSchema = EnrolledPartnerBasicSchema.extend({
clicks: z
.number()
+ .nullish()
.default(0)
.describe("The total number of clicks on the partner's links."),
leads: z
.number()
+ .nullish()
.default(0)
.describe("The total number of leads generated by the partner's links."),
sales: z
.number()
+ .nullish()
.default(0)
.describe("The total number of sales generated by the partner's links."),
saleAmount: z
.number()
+ .nullish()
.default(0)
.describe(
"The total amount of sales (in cents) generated by the partner's links.",
),
totalCommissions: z
.number()
+ .nullish()
.default(0)
.describe("The total commissions paid to the partner for their referrals."),
netRevenue: z
.number()
+ .nullish()
.default(0)
.describe("The total net revenue generated by the partner."),
earnings: z
.number()
+ .nullish()
.default(0)
.describe(
"DEPRECATED: The total earnings/commissions accrued by the partner's links.",