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.

Serialize cents and performanceCount from BigInt in APIs and Zod

Kiran K6af8c1ff9a66
diff --git a/apps/web/app/(ee)/api/partners/route.ts b/apps/web/app/(ee)/api/partners/route.ts
index 9211902e9f..52eb96911a 100644
--- a/apps/web/app/(ee)/api/partners/route.ts
+++ b/apps/web/app/(ee)/api/partners/route.ts
@@ -11,6 +11,7 @@ import {
getPartnersQuerySchemaExtended,
partnerPlatformSchema,
} from "@/lib/zod/schemas/partners";
+import { toCentsNumber } from "@dub/utils";
import { NextResponse } from "next/server";
import * as z from "zod/v4";
@@ -80,7 +81,7 @@ export const GET = withWorkspace(
leads: partner.totalLeads,
conversions: partner.totalConversions,
sales: partner.totalSales,
- saleAmount: partner.totalSaleAmount,
+ saleAmount: toCentsNumber(partner.totalSaleAmount),
...polyfillSocialMediaFields(partner.platforms),
})),
),
diff --git a/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
index eaf11d9904..ba1de49d3b 100644
--- a/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
+++ b/apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts
@@ -144,7 +144,7 @@ export const executeCompleteBountyWorkflow = async ({
const shouldExecute = evaluateWorkflowConditions({
conditions: [condition],
attributes: {
- [condition.attribute]: bountySubmission.performanceCount,
+ [condition.attribute]: Number(bountySubmission.performanceCount ?? 0),
},
});
diff --git a/apps/web/lib/zod/schemas/bounties.ts b/apps/web/lib/zod/schemas/bounties.ts
index cc4c3c63ec..e21dd35dd4 100644
--- a/apps/web/lib/zod/schemas/bounties.ts
+++ b/apps/web/lib/zod/schemas/bounties.ts
@@ -20,7 +20,7 @@ import { GroupSchema } from "./groups";
import { booleanQuerySchema, getPaginationQuerySchema } from "./misc";
import { EnrolledPartnerSchema } from "./partners";
import { UserSchema } from "./users";
-import { parseDateSchema } from "./utils";
+import { nullableCountSchema, parseDateSchema } from "./utils";
import { WORKFLOW_ATTRIBUTES } from "./workflows";
export const bountyPerformanceConditionSchema = z.object({
@@ -197,10 +197,9 @@ export const BountySubmissionSchema = z.object({
status: z
.enum(BountySubmissionStatus)
.meta({ description: "The status of the submission" }),
- performanceCount: z
- .number()
- .nullable()
- .meta({ description: "The performance count of the submission" }),
+ performanceCount: nullableCountSchema.meta({
+ description: "The performance count of the submission",
+ }),
socialMetricCount: z.number().int().nullable().meta({
description:
"The social metric count (views or likes) for the social content",
diff --git a/apps/web/lib/zod/schemas/utils.ts b/apps/web/lib/zod/schemas/utils.ts
index dd516c42dd..d37f98e834 100644
--- a/apps/web/lib/zod/schemas/utils.ts
+++ b/apps/web/lib/zod/schemas/utils.ts
@@ -5,9 +5,16 @@ import * as z from "zod/v4";
export const DESTINATION_URL_MAX_LENGTH = 32000;
/** Accepts number (before migration) or bigint (after), outputs number. */
-export const centsSchema = z
- .union([z.number(), z.bigint()])
- .transform((n) => (typeof n === "bigint" ? Number(n) : n));
+export const centsSchema = z.preprocess(
+ (n) => (typeof n === "bigint" ? Number(n) : n),
+ z.number(),
+);
+
+/** Accepts number or bigint or null (e.g. from Prisma BigInt?), outputs number | null. */
+export const nullableCountSchema = z.preprocess(
+ (n) => (typeof n === "bigint" ? Number(n) : n),
+ z.number().nullable(),
+);
export const parseUrlSchema = z
.string()
diff --git a/packages/prisma/schema/bounty.prisma b/packages/prisma/schema/bounty.prisma
index 5f49b42563..ec480bab03 100644
--- a/packages/prisma/schema/bounty.prisma
+++ b/packages/prisma/schema/bounty.prisma
@@ -76,7 +76,7 @@ model BountySubmission {
programId String
partnerId String
bountyId String
- performanceCount Int?
+ performanceCount BigInt?
socialMetricCount Int?
commissionId String? @unique
userId String?