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.

Move attribute validators into validate-group-move-rules

Kiran K8342b7e49642
diff --git a/apps/web/lib/api/groups/validate-group-move-rules.ts b/apps/web/lib/api/groups/validate-group-move-rules.ts
index 3a4062f4eb..62c46f9f7a 100644
--- a/apps/web/lib/api/groups/validate-group-move-rules.ts
+++ b/apps/web/lib/api/groups/validate-group-move-rules.ts
@@ -1,12 +1,31 @@
import {
GROUP_MOVE_ATTRIBUTE_CONFIG,
- GROUP_MOVE_ATTRIBUTE_VALIDATORS,
GROUP_MOVE_OPERATOR_LABELS,
GROUP_MOVE_OPERATOR_VALIDATORS,
+ GroupMoveAttribute,
type GroupMoveCondition,
type GroupMoveRules,
} from "@/lib/zod/schemas/group-move-workflows";
+type GroupMoveAttributeValidator = (params: {
+ rule: GroupMoveCondition;
+ ruleIndex: number;
+ destinationGroupId: string;
+}) => void;
+
+// Add business rules for each attribute
+// NOTE: Keeping this empty for now, next PR will use this
+const GROUP_MOVE_ATTRIBUTE_VALIDATORS: Record<
+ GroupMoveAttribute,
+ GroupMoveAttributeValidator
+> = {
+ // Operator validators already cover performance value shape/constraints.
+ totalLeads: () => {},
+ totalConversions: () => {},
+ totalSaleAmount: () => {},
+ totalCommissions: () => {},
+};
+
export const validateGroupMoveRules = ({
rules,
destinationGroupId,
@@ -65,7 +84,10 @@ const validateRule = ({
];
if (validateOperator) {
- validateOperator(rule, ruleIndex);
+ validateOperator({
+ rule,
+ ruleIndex,
+ });
}
// Validate attribute-specific constraints (business rules)
diff --git a/apps/web/lib/zod/schemas/group-move-workflows.ts b/apps/web/lib/zod/schemas/group-move-workflows.ts
index 2068b2acb9..2a210287a9 100644
--- a/apps/web/lib/zod/schemas/group-move-workflows.ts
+++ b/apps/web/lib/zod/schemas/group-move-workflows.ts
@@ -55,7 +55,7 @@ export const groupMoveConditionSchema = z.object({
export const groupMoveRulesSchema = z.array(groupMoveConditionSchema);
export const GROUP_MOVE_OPERATOR_VALIDATORS = {
- gte(rule: GroupMoveCondition, ruleIndex: number) {
+ gte({ rule, ruleIndex }: GroupMoveAttributeValidatorArgs) {
if (
typeof rule.value !== "number" ||
isNaN(rule.value) ||
@@ -67,7 +67,7 @@ export const GROUP_MOVE_OPERATOR_VALIDATORS = {
}
},
- between(rule: GroupMoveCondition, ruleIndex: number) {
+ between({ rule, ruleIndex }: GroupMoveAttributeValidatorArgs) {
if (typeof rule.value !== "object" || rule.value === null) {
throw new Error(`Rule ${ruleIndex + 1}: Please enter a valid value.`);
}
@@ -96,19 +96,6 @@ export const GROUP_MOVE_OPERATOR_VALIDATORS = {
},
} as const;
-// Add business rules for each attribute
-// Keeping this empty for now
-export const GROUP_MOVE_ATTRIBUTE_VALIDATORS: Record<
- GroupMoveAttribute,
- GroupMoveAttributeValidator
-> = {
- // Operator validators already cover performance value shape/constraints.
- totalLeads: () => {},
- totalConversions: () => {},
- totalSaleAmount: () => {},
- totalCommissions: () => {},
-};
-
export type GroupMoveCondition = z.infer<typeof groupMoveConditionSchema>;
export type GroupMoveRules = z.infer<typeof groupMoveRulesSchema>;
@@ -126,9 +113,4 @@ export type GroupMoveAttributeConfig = {
type GroupMoveAttributeValidatorArgs = {
rule: GroupMoveCondition;
ruleIndex: number;
- destinationGroupId: string;
};
-
-type GroupMoveAttributeValidator = (
- params: GroupMoveAttributeValidatorArgs,
-) => void;