@zyacreatives/shared 2.2.96 → 2.2.97
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/schemas/product.js +29 -9
- package/package.json +1 -1
- package/src/schemas/product.ts +36 -9
package/dist/schemas/product.js
CHANGED
|
@@ -100,15 +100,15 @@ exports.CreateProductInputSchema = ProductCoreInputSchema.superRefine((data, ctx
|
|
|
100
100
|
path: ["price"],
|
|
101
101
|
});
|
|
102
102
|
}
|
|
103
|
-
if (data.pricingModel === constants_1.PRICING_MODELS.PWYW
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
}
|
|
103
|
+
if (data.pricingModel === constants_1.PRICING_MODELS.PWYW &&
|
|
104
|
+
data.suggestedPrice !== undefined &&
|
|
105
|
+
data.price !== undefined) {
|
|
106
|
+
if (data.suggestedPrice < data.price) {
|
|
107
|
+
ctx.addIssue({
|
|
108
|
+
code: "custom",
|
|
109
|
+
message: "Suggested price cannot be lower than the minimum price.",
|
|
110
|
+
path: ["suggestedPrice"],
|
|
111
|
+
});
|
|
112
112
|
}
|
|
113
113
|
}
|
|
114
114
|
if (data.pricingModel === constants_1.PRICING_MODELS.FREE &&
|
|
@@ -135,6 +135,26 @@ exports.CreateProductInputSchema = ProductCoreInputSchema.superRefine((data, ctx
|
|
|
135
135
|
path: ["coverImages"],
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
+
data.discounts.forEach((discount, index) => {
|
|
139
|
+
const isPercentage = String(discount.discountType).toUpperCase() === "PERCENTAGE";
|
|
140
|
+
const isFixed = String(discount.discountType).toUpperCase() === "FIXED";
|
|
141
|
+
if (isPercentage && discount.amount >= 100) {
|
|
142
|
+
ctx.addIssue({
|
|
143
|
+
code: "custom",
|
|
144
|
+
message: "Percentage discounts must be less than 100%.",
|
|
145
|
+
path: ["discounts", index, "amount"],
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
if (isFixed && data.price !== undefined) {
|
|
149
|
+
if (discount.amount >= data.price) {
|
|
150
|
+
ctx.addIssue({
|
|
151
|
+
code: "custom",
|
|
152
|
+
message: "Fixed discount amounts must be less than the product price.",
|
|
153
|
+
path: ["discounts", index, "amount"],
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
});
|
|
138
158
|
});
|
|
139
159
|
exports.ProductServiceAndComplianceInputSchema = zod_openapi_1.z.object({
|
|
140
160
|
id: zod_openapi_1.z.cuid2().openapi({ description: "ID of the product" }),
|
package/package.json
CHANGED
package/src/schemas/product.ts
CHANGED
|
@@ -130,15 +130,17 @@ export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
|
|
|
130
130
|
});
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
if (
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
133
|
+
if (
|
|
134
|
+
data.pricingModel === PRICING_MODELS.PWYW &&
|
|
135
|
+
data.suggestedPrice !== undefined &&
|
|
136
|
+
data.price !== undefined
|
|
137
|
+
) {
|
|
138
|
+
if (data.suggestedPrice < data.price) {
|
|
139
|
+
ctx.addIssue({
|
|
140
|
+
code: "custom",
|
|
141
|
+
message: "Suggested price cannot be lower than the minimum price.",
|
|
142
|
+
path: ["suggestedPrice"],
|
|
143
|
+
});
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
|
|
@@ -171,6 +173,31 @@ export const CreateProductInputSchema = ProductCoreInputSchema.superRefine(
|
|
|
171
173
|
path: ["coverImages"],
|
|
172
174
|
});
|
|
173
175
|
}
|
|
176
|
+
|
|
177
|
+
data.discounts.forEach((discount, index) => {
|
|
178
|
+
const isPercentage =
|
|
179
|
+
String(discount.discountType).toUpperCase() === "PERCENTAGE";
|
|
180
|
+
const isFixed = String(discount.discountType).toUpperCase() === "FIXED";
|
|
181
|
+
|
|
182
|
+
if (isPercentage && discount.amount >= 100) {
|
|
183
|
+
ctx.addIssue({
|
|
184
|
+
code: "custom",
|
|
185
|
+
message: "Percentage discounts must be less than 100%.",
|
|
186
|
+
path: ["discounts", index, "amount"],
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (isFixed && data.price !== undefined) {
|
|
191
|
+
if (discount.amount >= data.price) {
|
|
192
|
+
ctx.addIssue({
|
|
193
|
+
code: "custom",
|
|
194
|
+
message:
|
|
195
|
+
"Fixed discount amounts must be less than the product price.",
|
|
196
|
+
path: ["discounts", index, "amount"],
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
});
|
|
174
201
|
},
|
|
175
202
|
);
|
|
176
203
|
|