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 `totalCommissions` to use `centsSchemaWithDefault` in `ProgramEnrollmentSchema` for improved default handling; update `toCentsNumber` function formatting for better readability.

Kiran K54ca76fe9e51
diff --git a/apps/web/lib/zod/schemas/programs.ts b/apps/web/lib/zod/schemas/programs.ts
index 720ddb8855..9597522c62 100644
--- a/apps/web/lib/zod/schemas/programs.ts
+++ b/apps/web/lib/zod/schemas/programs.ts
@@ -23,7 +23,7 @@ import { programInviteEmailDataSchema } from "./program-invite-email";
import { referralFormSchema } from "./referral-form";
import { RewardSchema } from "./rewards";
import { UserSchema } from "./users";
-import { parseDateSchema, centsSchema } from "./utils";
+import { centsSchemaWithDefault, parseDateSchema } from "./utils";
export const ProgramSchema = z.object({
id: z.string(),
@@ -111,7 +111,7 @@ export const ProgramEnrollmentSchema = z.object({
.array(ProgramPartnerLinkSchema)
.nullable()
.describe("The partner's referral links in this program."),
- totalCommissions: centsSchema.default(0),
+ totalCommissions: centsSchemaWithDefault,
rewards: z.array(RewardSchema).nullish(),
clickRewardId: z.string().nullish(),
leadRewardId: z.string().nullish(),
diff --git a/packages/utils/src/functions/to-cents-number.ts b/packages/utils/src/functions/to-cents-number.ts
index 5f16eb731e..fabf9f087a 100644
--- a/packages/utils/src/functions/to-cents-number.ts
+++ b/packages/utils/src/functions/to-cents-number.ts
@@ -2,7 +2,9 @@
* Normalize a cents value from Prisma (number before migration, bigint after) to number.
* Use for display, JSON serialization, and anywhere a number is required.
*/
-export function toCentsNumber(value: number | bigint | null | undefined): number {
+export function toCentsNumber(
+ value: number | bigint | null | undefined,
+): number {
if (value == null) return 0;
return typeof value === "bigint" ? Number(value) : value;
}