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.

add schema changes

Kiran K5ce7766522d3
diff --git a/apps/web/lib/zod/schemas/rewards.ts b/apps/web/lib/zod/schemas/rewards.ts
index 0ff9903230..9a84055ed6 100644
--- a/apps/web/lib/zod/schemas/rewards.ts
+++ b/apps/web/lib/zod/schemas/rewards.ts
@@ -15,6 +15,23 @@ export const COMMISSION_TYPES = [
},
] as const;
+export const LIMIT_RESET_OPTIONS = [
+ { label: "Lifetime", value: "" },
+ { label: "1 year", value: "12" },
+ { label: "6 months", value: "6" },
+ { label: "3 months", value: "3" },
+ { label: "1 month", value: "1" },
+] as const;
+
+const payoutResetIntervalSchema = z
+ .coerce
+ .number()
+ .nullish()
+ .default(null)
+ .refine((val) => val === null || LIMIT_RESET_OPTIONS.some((o) => o.value === val.toString()), {
+ message: "Invalid payout reset interval",
+ });
+
export const RewardSchema = z.object({
id: z.string(),
event: z.nativeEnum(EventType),
@@ -24,16 +41,20 @@ export const RewardSchema = z.object({
amount: z.number(),
maxDuration: z.number().nullish(),
partnersCount: z.number().nullish(),
+ maxTotalPayout: z.number().nullish(),
+ payoutResetInterval: payoutResetIntervalSchema,
});
export const createOrUpdateRewardSchema = z.object({
+ workspaceId: z.string(),
+ programId: z.string(),
event: z.nativeEnum(EventType),
type: z.nativeEnum(CommissionType).default("flat"),
amount: z.number().min(0),
maxDuration: maxDurationSchema,
partnerIds: z.array(z.string()).nullish(),
- workspaceId: z.string(),
- programId: z.string(),
+ maxTotalPayout: z.number().nullish(),
+ payoutResetInterval: payoutResetIntervalSchema,
});
export const createRewardSchema = createOrUpdateRewardSchema.superRefine(
diff --git a/packages/prisma/schema/reward.prisma b/packages/prisma/schema/reward.prisma
index 5b91f0dc4a..21e057a2af 100644
--- a/packages/prisma/schema/reward.prisma
+++ b/packages/prisma/schema/reward.prisma
@@ -9,6 +9,9 @@ model Reward {
amount Int @default(0)
maxDuration Int? // in months (0 -> not recurring, null -> infinite)
+ maxTotalPayout Int? // how much a partner can receive payouts
+ payoutResetInterval Int? // how often the max amount is reset (in months)
+
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt