vr-commons 1.0.94 → 1.0.96

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.
@@ -8,4 +8,5 @@ export { unlockDeviceSchema, extendSessionSchema } from "./devices.validations";
8
8
  export { payInstallmentSchema } from "./payinstallment.validations";
9
9
  export { updateProfileSchema, requestPhoneChangeSchema, verifyPhoneChangeSchema, deleteAccountSchema, strongPasswordRegex, changePasswordSchema, } from "./account.validations";
10
10
  export { updateAdminSchema, updateRiderSchema, deleteUserSchema, getUserSchema, getUsersSchema, hireAdminSchema, promoteAdminSchema, demoteAdminSchema, fireEmployeeSchema, upgradeToRiderSchema, resetPasswordSchema, } from "./users.admin.validations";
11
- export { createProductSchema, updateProductSchema, getProductSchema, getProductsSchema, deactivateProductSchema, activateProductSchema, deleteProductSchema, } from "./product.validations";
11
+ export { createProductSchema, updateProductSchema, getProductSchema, getProductsSchema, deactivateProductSchema, activateProductSchema, deleteProductSchema, updateStockSchema, } from "./product.validations";
12
+ export { createPricingSchema, updatePricingSchema, getPricingSchema, getPricingsSchema, deletePricingSchema, } from "./pricings.validations";
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.verifyPhoneChangeSchema = exports.requestPhoneChangeSchema = exports.updateProfileSchema = exports.payInstallmentSchema = exports.extendSessionSchema = exports.unlockDeviceSchema = exports.getUserPaymentPlanSchema = exports.listUserPaymentPlansSchema = exports.getAppSpecsSchema = exports.activateAppSpecsSchema = exports.getActiveAppSpecsSchema = exports.listAppSpecsSchema = exports.updateAppSpecsSchema = exports.createAppSpecsSchema = exports.exportBansSchema = exports.createSuspensionSchema = exports.createBanSchema = exports.extendSuspensionSchema = exports.revokeSuspensionSchema = exports.revokeBanSchema = exports.reviewAppealSchema = exports.listSuspensionsSchema = exports.listPendingAppealsSchema = exports.listBansSchema = exports.getUserBansSchema = exports.getUserSuspensionsSchema = exports.getSuspensionSchema = exports.getUserRestrictionsSchema = exports.getBanSchema = exports.submitSuspensionAppealSchema = exports.submitBanAppealSchema = exports.deactivateAccountSchema = exports.createRiderSchema = exports.updateRiderProfileSchema = exports.updatePassengerProfileSchema = exports.passengerSignupSchema = exports.viewProfileSchema = exports.getAllUsersSchema = exports.updateUserProfileSchema = exports.getUserByIdSchema = exports.createUserSchema = exports.requestOtpSchema = exports.resendOtpSchema = exports.verifyOtpSchema = exports.registerSchema = exports.refreshTokenSchema = exports.userLoginSchema = exports.forgotPasswordSchema = exports.riderLoginSchema = exports.validate = void 0;
4
- exports.deleteProductSchema = exports.activateProductSchema = exports.deactivateProductSchema = exports.getProductsSchema = exports.getProductSchema = exports.updateProductSchema = exports.createProductSchema = exports.resetPasswordSchema = exports.upgradeToRiderSchema = exports.fireEmployeeSchema = exports.demoteAdminSchema = exports.promoteAdminSchema = exports.hireAdminSchema = exports.getUsersSchema = exports.getUserSchema = exports.deleteUserSchema = exports.updateRiderSchema = exports.updateAdminSchema = exports.changePasswordSchema = exports.strongPasswordRegex = exports.deleteAccountSchema = void 0;
4
+ exports.deletePricingSchema = exports.getPricingsSchema = exports.getPricingSchema = exports.updatePricingSchema = exports.createPricingSchema = exports.updateStockSchema = exports.deleteProductSchema = exports.activateProductSchema = exports.deactivateProductSchema = exports.getProductsSchema = exports.getProductSchema = exports.updateProductSchema = exports.createProductSchema = exports.resetPasswordSchema = exports.upgradeToRiderSchema = exports.fireEmployeeSchema = exports.demoteAdminSchema = exports.promoteAdminSchema = exports.hireAdminSchema = exports.getUsersSchema = exports.getUserSchema = exports.deleteUserSchema = exports.updateRiderSchema = exports.updateAdminSchema = exports.changePasswordSchema = exports.strongPasswordRegex = exports.deleteAccountSchema = void 0;
5
5
  var validate_validations_1 = require("./validate.validations");
6
6
  Object.defineProperty(exports, "validate", { enumerable: true, get: function () { return validate_validations_1.validate; } });
7
7
  var auth_validations_1 = require("./auth.validations");
@@ -92,3 +92,10 @@ Object.defineProperty(exports, "getProductsSchema", { enumerable: true, get: fun
92
92
  Object.defineProperty(exports, "deactivateProductSchema", { enumerable: true, get: function () { return product_validations_1.deactivateProductSchema; } });
93
93
  Object.defineProperty(exports, "activateProductSchema", { enumerable: true, get: function () { return product_validations_1.activateProductSchema; } });
94
94
  Object.defineProperty(exports, "deleteProductSchema", { enumerable: true, get: function () { return product_validations_1.deleteProductSchema; } });
95
+ Object.defineProperty(exports, "updateStockSchema", { enumerable: true, get: function () { return product_validations_1.updateStockSchema; } });
96
+ var pricings_validations_1 = require("./pricings.validations");
97
+ Object.defineProperty(exports, "createPricingSchema", { enumerable: true, get: function () { return pricings_validations_1.createPricingSchema; } });
98
+ Object.defineProperty(exports, "updatePricingSchema", { enumerable: true, get: function () { return pricings_validations_1.updatePricingSchema; } });
99
+ Object.defineProperty(exports, "getPricingSchema", { enumerable: true, get: function () { return pricings_validations_1.getPricingSchema; } });
100
+ Object.defineProperty(exports, "getPricingsSchema", { enumerable: true, get: function () { return pricings_validations_1.getPricingsSchema; } });
101
+ Object.defineProperty(exports, "deletePricingSchema", { enumerable: true, get: function () { return pricings_validations_1.deletePricingSchema; } });
@@ -0,0 +1,313 @@
1
+ import { z } from "zod";
2
+ export declare const createPricingSchema: z.ZodObject<{
3
+ body: z.ZodEffects<z.ZodObject<{
4
+ productId: z.ZodString;
5
+ name: z.ZodString;
6
+ type: z.ZodEnum<["HIRE_PURCHASE", "FULL_PAYMENT"]>;
7
+ totalAmount: z.ZodNumber;
8
+ downPayment: z.ZodOptional<z.ZodNumber>;
9
+ installmentAmount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
10
+ installmentFrequency: z.ZodOptional<z.ZodNullable<z.ZodEnum<["DAILY", "WEEKLY", "MONTHLY"]>>>;
11
+ installmentCount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
12
+ gracePeriodDays: z.ZodOptional<z.ZodNumber>;
13
+ autoLockOnMiss: z.ZodOptional<z.ZodBoolean>;
14
+ minOrderQuantity: z.ZodOptional<z.ZodNumber>;
15
+ maxOrderQuantity: z.ZodOptional<z.ZodNumber>;
16
+ isActive: z.ZodOptional<z.ZodBoolean>;
17
+ }, "strip", z.ZodTypeAny, {
18
+ productId: string;
19
+ name: string;
20
+ type: "HIRE_PURCHASE" | "FULL_PAYMENT";
21
+ totalAmount: number;
22
+ downPayment?: number | undefined;
23
+ installmentAmount?: number | null | undefined;
24
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
25
+ installmentCount?: number | null | undefined;
26
+ gracePeriodDays?: number | undefined;
27
+ autoLockOnMiss?: boolean | undefined;
28
+ minOrderQuantity?: number | undefined;
29
+ maxOrderQuantity?: number | undefined;
30
+ isActive?: boolean | undefined;
31
+ }, {
32
+ productId: string;
33
+ name: string;
34
+ type: "HIRE_PURCHASE" | "FULL_PAYMENT";
35
+ totalAmount: number;
36
+ downPayment?: number | undefined;
37
+ installmentAmount?: number | null | undefined;
38
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
39
+ installmentCount?: number | null | undefined;
40
+ gracePeriodDays?: number | undefined;
41
+ autoLockOnMiss?: boolean | undefined;
42
+ minOrderQuantity?: number | undefined;
43
+ maxOrderQuantity?: number | undefined;
44
+ isActive?: boolean | undefined;
45
+ }>, {
46
+ productId: string;
47
+ name: string;
48
+ type: "HIRE_PURCHASE" | "FULL_PAYMENT";
49
+ totalAmount: number;
50
+ downPayment?: number | undefined;
51
+ installmentAmount?: number | null | undefined;
52
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
53
+ installmentCount?: number | null | undefined;
54
+ gracePeriodDays?: number | undefined;
55
+ autoLockOnMiss?: boolean | undefined;
56
+ minOrderQuantity?: number | undefined;
57
+ maxOrderQuantity?: number | undefined;
58
+ isActive?: boolean | undefined;
59
+ }, {
60
+ productId: string;
61
+ name: string;
62
+ type: "HIRE_PURCHASE" | "FULL_PAYMENT";
63
+ totalAmount: number;
64
+ downPayment?: number | undefined;
65
+ installmentAmount?: number | null | undefined;
66
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
67
+ installmentCount?: number | null | undefined;
68
+ gracePeriodDays?: number | undefined;
69
+ autoLockOnMiss?: boolean | undefined;
70
+ minOrderQuantity?: number | undefined;
71
+ maxOrderQuantity?: number | undefined;
72
+ isActive?: boolean | undefined;
73
+ }>;
74
+ }, "strip", z.ZodTypeAny, {
75
+ body: {
76
+ productId: string;
77
+ name: string;
78
+ type: "HIRE_PURCHASE" | "FULL_PAYMENT";
79
+ totalAmount: number;
80
+ downPayment?: number | undefined;
81
+ installmentAmount?: number | null | undefined;
82
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
83
+ installmentCount?: number | null | undefined;
84
+ gracePeriodDays?: number | undefined;
85
+ autoLockOnMiss?: boolean | undefined;
86
+ minOrderQuantity?: number | undefined;
87
+ maxOrderQuantity?: number | undefined;
88
+ isActive?: boolean | undefined;
89
+ };
90
+ }, {
91
+ body: {
92
+ productId: string;
93
+ name: string;
94
+ type: "HIRE_PURCHASE" | "FULL_PAYMENT";
95
+ totalAmount: number;
96
+ downPayment?: number | undefined;
97
+ installmentAmount?: number | null | undefined;
98
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
99
+ installmentCount?: number | null | undefined;
100
+ gracePeriodDays?: number | undefined;
101
+ autoLockOnMiss?: boolean | undefined;
102
+ minOrderQuantity?: number | undefined;
103
+ maxOrderQuantity?: number | undefined;
104
+ isActive?: boolean | undefined;
105
+ };
106
+ }>;
107
+ export declare const updatePricingSchema: z.ZodObject<{
108
+ params: z.ZodObject<{
109
+ id: z.ZodString;
110
+ }, "strip", z.ZodTypeAny, {
111
+ id: string;
112
+ }, {
113
+ id: string;
114
+ }>;
115
+ body: z.ZodEffects<z.ZodObject<{
116
+ name: z.ZodOptional<z.ZodString>;
117
+ type: z.ZodOptional<z.ZodEnum<["HIRE_PURCHASE", "FULL_PAYMENT"]>>;
118
+ totalAmount: z.ZodOptional<z.ZodNumber>;
119
+ downPayment: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
120
+ installmentAmount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
121
+ installmentFrequency: z.ZodOptional<z.ZodNullable<z.ZodEnum<["DAILY", "WEEKLY", "MONTHLY"]>>>;
122
+ installmentCount: z.ZodOptional<z.ZodNullable<z.ZodNumber>>;
123
+ gracePeriodDays: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
124
+ autoLockOnMiss: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
125
+ minOrderQuantity: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
126
+ maxOrderQuantity: z.ZodOptional<z.ZodOptional<z.ZodNumber>>;
127
+ isActive: z.ZodOptional<z.ZodOptional<z.ZodBoolean>>;
128
+ }, "strip", z.ZodTypeAny, {
129
+ name?: string | undefined;
130
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
131
+ totalAmount?: number | undefined;
132
+ downPayment?: number | undefined;
133
+ installmentAmount?: number | null | undefined;
134
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
135
+ installmentCount?: number | null | undefined;
136
+ gracePeriodDays?: number | undefined;
137
+ autoLockOnMiss?: boolean | undefined;
138
+ minOrderQuantity?: number | undefined;
139
+ maxOrderQuantity?: number | undefined;
140
+ isActive?: boolean | undefined;
141
+ }, {
142
+ name?: string | undefined;
143
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
144
+ totalAmount?: number | undefined;
145
+ downPayment?: number | undefined;
146
+ installmentAmount?: number | null | undefined;
147
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
148
+ installmentCount?: number | null | undefined;
149
+ gracePeriodDays?: number | undefined;
150
+ autoLockOnMiss?: boolean | undefined;
151
+ minOrderQuantity?: number | undefined;
152
+ maxOrderQuantity?: number | undefined;
153
+ isActive?: boolean | undefined;
154
+ }>, {
155
+ name?: string | undefined;
156
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
157
+ totalAmount?: number | undefined;
158
+ downPayment?: number | undefined;
159
+ installmentAmount?: number | null | undefined;
160
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
161
+ installmentCount?: number | null | undefined;
162
+ gracePeriodDays?: number | undefined;
163
+ autoLockOnMiss?: boolean | undefined;
164
+ minOrderQuantity?: number | undefined;
165
+ maxOrderQuantity?: number | undefined;
166
+ isActive?: boolean | undefined;
167
+ }, {
168
+ name?: string | undefined;
169
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
170
+ totalAmount?: number | undefined;
171
+ downPayment?: number | undefined;
172
+ installmentAmount?: number | null | undefined;
173
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
174
+ installmentCount?: number | null | undefined;
175
+ gracePeriodDays?: number | undefined;
176
+ autoLockOnMiss?: boolean | undefined;
177
+ minOrderQuantity?: number | undefined;
178
+ maxOrderQuantity?: number | undefined;
179
+ isActive?: boolean | undefined;
180
+ }>;
181
+ }, "strip", z.ZodTypeAny, {
182
+ params: {
183
+ id: string;
184
+ };
185
+ body: {
186
+ name?: string | undefined;
187
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
188
+ totalAmount?: number | undefined;
189
+ downPayment?: number | undefined;
190
+ installmentAmount?: number | null | undefined;
191
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
192
+ installmentCount?: number | null | undefined;
193
+ gracePeriodDays?: number | undefined;
194
+ autoLockOnMiss?: boolean | undefined;
195
+ minOrderQuantity?: number | undefined;
196
+ maxOrderQuantity?: number | undefined;
197
+ isActive?: boolean | undefined;
198
+ };
199
+ }, {
200
+ params: {
201
+ id: string;
202
+ };
203
+ body: {
204
+ name?: string | undefined;
205
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
206
+ totalAmount?: number | undefined;
207
+ downPayment?: number | undefined;
208
+ installmentAmount?: number | null | undefined;
209
+ installmentFrequency?: "DAILY" | "WEEKLY" | "MONTHLY" | null | undefined;
210
+ installmentCount?: number | null | undefined;
211
+ gracePeriodDays?: number | undefined;
212
+ autoLockOnMiss?: boolean | undefined;
213
+ minOrderQuantity?: number | undefined;
214
+ maxOrderQuantity?: number | undefined;
215
+ isActive?: boolean | undefined;
216
+ };
217
+ }>;
218
+ export declare const getPricingSchema: z.ZodObject<{
219
+ params: z.ZodObject<{
220
+ id: z.ZodString;
221
+ }, "strip", z.ZodTypeAny, {
222
+ id: string;
223
+ }, {
224
+ id: string;
225
+ }>;
226
+ }, "strip", z.ZodTypeAny, {
227
+ params: {
228
+ id: string;
229
+ };
230
+ }, {
231
+ params: {
232
+ id: string;
233
+ };
234
+ }>;
235
+ export declare const getPricingsSchema: z.ZodObject<{
236
+ query: z.ZodObject<{
237
+ page: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
238
+ limit: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
239
+ productId: z.ZodOptional<z.ZodString>;
240
+ type: z.ZodOptional<z.ZodEnum<["HIRE_PURCHASE", "FULL_PAYMENT"]>>;
241
+ isActive: z.ZodOptional<z.ZodEnum<["true", "false"]>>;
242
+ minAmount: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
243
+ maxAmount: z.ZodOptional<z.ZodEffects<z.ZodString, number, string>>;
244
+ search: z.ZodOptional<z.ZodString>;
245
+ sortBy: z.ZodOptional<z.ZodEnum<["name", "totalAmount", "createdAt", "updatedAt"]>>;
246
+ sortOrder: z.ZodOptional<z.ZodEnum<["ASC", "DESC"]>>;
247
+ }, "strip", z.ZodTypeAny, {
248
+ productId?: string | undefined;
249
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
250
+ isActive?: "true" | "false" | undefined;
251
+ page?: number | undefined;
252
+ limit?: number | undefined;
253
+ minAmount?: number | undefined;
254
+ maxAmount?: number | undefined;
255
+ search?: string | undefined;
256
+ sortBy?: "name" | "totalAmount" | "createdAt" | "updatedAt" | undefined;
257
+ sortOrder?: "ASC" | "DESC" | undefined;
258
+ }, {
259
+ productId?: string | undefined;
260
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
261
+ isActive?: "true" | "false" | undefined;
262
+ page?: string | undefined;
263
+ limit?: string | undefined;
264
+ minAmount?: string | undefined;
265
+ maxAmount?: string | undefined;
266
+ search?: string | undefined;
267
+ sortBy?: "name" | "totalAmount" | "createdAt" | "updatedAt" | undefined;
268
+ sortOrder?: "ASC" | "DESC" | undefined;
269
+ }>;
270
+ }, "strip", z.ZodTypeAny, {
271
+ query: {
272
+ productId?: string | undefined;
273
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
274
+ isActive?: "true" | "false" | undefined;
275
+ page?: number | undefined;
276
+ limit?: number | undefined;
277
+ minAmount?: number | undefined;
278
+ maxAmount?: number | undefined;
279
+ search?: string | undefined;
280
+ sortBy?: "name" | "totalAmount" | "createdAt" | "updatedAt" | undefined;
281
+ sortOrder?: "ASC" | "DESC" | undefined;
282
+ };
283
+ }, {
284
+ query: {
285
+ productId?: string | undefined;
286
+ type?: "HIRE_PURCHASE" | "FULL_PAYMENT" | undefined;
287
+ isActive?: "true" | "false" | undefined;
288
+ page?: string | undefined;
289
+ limit?: string | undefined;
290
+ minAmount?: string | undefined;
291
+ maxAmount?: string | undefined;
292
+ search?: string | undefined;
293
+ sortBy?: "name" | "totalAmount" | "createdAt" | "updatedAt" | undefined;
294
+ sortOrder?: "ASC" | "DESC" | undefined;
295
+ };
296
+ }>;
297
+ export declare const deletePricingSchema: z.ZodObject<{
298
+ params: z.ZodObject<{
299
+ id: z.ZodString;
300
+ }, "strip", z.ZodTypeAny, {
301
+ id: string;
302
+ }, {
303
+ id: string;
304
+ }>;
305
+ }, "strip", z.ZodTypeAny, {
306
+ params: {
307
+ id: string;
308
+ };
309
+ }, {
310
+ params: {
311
+ id: string;
312
+ };
313
+ }>;
@@ -0,0 +1,376 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.deletePricingSchema = exports.getPricingsSchema = exports.getPricingSchema = exports.updatePricingSchema = exports.createPricingSchema = void 0;
4
+ // src/validations/pricing.validation.ts
5
+ const zod_1 = require("zod");
6
+ // Constants
7
+ const PRICING_TYPES = ["HIRE_PURCHASE", "FULL_PAYMENT"];
8
+ const INSTALLMENT_FREQUENCIES = ["DAILY", "WEEKLY", "MONTHLY"];
9
+ // Base pricing schema
10
+ const pricingBaseSchema = {
11
+ productId: zod_1.z.string().uuid("Invalid product ID"),
12
+ name: zod_1.z.string().min(3, "Name must be at least 3 characters").max(100),
13
+ type: zod_1.z.enum(PRICING_TYPES, {
14
+ errorMap: () => ({ message: "Type must be HIRE_PURCHASE or FULL_PAYMENT" }),
15
+ }),
16
+ totalAmount: zod_1.z.number().min(0, "Total amount cannot be negative"),
17
+ downPayment: zod_1.z.number().min(0, "Down payment cannot be negative").optional(),
18
+ installmentAmount: zod_1.z
19
+ .number()
20
+ .min(0, "Installment amount cannot be negative")
21
+ .nullable()
22
+ .optional(),
23
+ installmentFrequency: zod_1.z.enum(INSTALLMENT_FREQUENCIES).nullable().optional(),
24
+ installmentCount: zod_1.z
25
+ .number()
26
+ .int()
27
+ .min(1, "Installment count must be at least 1")
28
+ .nullable()
29
+ .optional(),
30
+ gracePeriodDays: zod_1.z
31
+ .number()
32
+ .int()
33
+ .min(0, "Grace period cannot be negative")
34
+ .max(30, "Grace period too long")
35
+ .optional(),
36
+ autoLockOnMiss: zod_1.z.boolean().optional(),
37
+ // NEW FIELDS
38
+ minOrderQuantity: zod_1.z
39
+ .number()
40
+ .int()
41
+ .min(1, "Minimum order quantity must be at least 1")
42
+ .optional(),
43
+ maxOrderQuantity: zod_1.z
44
+ .number()
45
+ .int()
46
+ .min(1, "Maximum order quantity must be at least 1")
47
+ .optional(),
48
+ isActive: zod_1.z.boolean().optional(),
49
+ };
50
+ // Create pricing schema with STRICT validation
51
+ exports.createPricingSchema = zod_1.z.object({
52
+ body: zod_1.z
53
+ .object({
54
+ productId: pricingBaseSchema.productId,
55
+ name: pricingBaseSchema.name,
56
+ type: pricingBaseSchema.type,
57
+ totalAmount: pricingBaseSchema.totalAmount,
58
+ downPayment: pricingBaseSchema.downPayment,
59
+ installmentAmount: pricingBaseSchema.installmentAmount,
60
+ installmentFrequency: pricingBaseSchema.installmentFrequency,
61
+ installmentCount: pricingBaseSchema.installmentCount,
62
+ gracePeriodDays: pricingBaseSchema.gracePeriodDays,
63
+ autoLockOnMiss: pricingBaseSchema.autoLockOnMiss,
64
+ minOrderQuantity: pricingBaseSchema.minOrderQuantity,
65
+ maxOrderQuantity: pricingBaseSchema.maxOrderQuantity,
66
+ isActive: pricingBaseSchema.isActive,
67
+ })
68
+ .superRefine((data, ctx) => {
69
+ // Validate minOrderQuantity <= maxOrderQuantity
70
+ const minQty = data.minOrderQuantity ?? 1;
71
+ const maxQty = data.maxOrderQuantity ?? 1;
72
+ if (minQty > maxQty) {
73
+ ctx.addIssue({
74
+ code: zod_1.z.ZodIssueCode.custom,
75
+ message: "Minimum order quantity cannot be greater than maximum order quantity",
76
+ path: ["minOrderQuantity"],
77
+ });
78
+ }
79
+ // HIRE_PURCHASE validation
80
+ if (data.type === "HIRE_PURCHASE") {
81
+ // Must have downPayment (can be 0, but must be present)
82
+ if (data.downPayment === undefined) {
83
+ ctx.addIssue({
84
+ code: zod_1.z.ZodIssueCode.custom,
85
+ message: "Down payment is required for hire purchase",
86
+ path: ["downPayment"],
87
+ });
88
+ }
89
+ // Must have installmentAmount
90
+ if (!data.installmentAmount || data.installmentAmount <= 0) {
91
+ ctx.addIssue({
92
+ code: zod_1.z.ZodIssueCode.custom,
93
+ message: "Installment amount is required and must be > 0 for hire purchase",
94
+ path: ["installmentAmount"],
95
+ });
96
+ }
97
+ // Must have installmentFrequency
98
+ if (!data.installmentFrequency) {
99
+ ctx.addIssue({
100
+ code: zod_1.z.ZodIssueCode.custom,
101
+ message: "Installment frequency is required for hire purchase",
102
+ path: ["installmentFrequency"],
103
+ });
104
+ }
105
+ // Must have installmentCount
106
+ if (!data.installmentCount || data.installmentCount <= 0) {
107
+ ctx.addIssue({
108
+ code: zod_1.z.ZodIssueCode.custom,
109
+ message: "Installment count is required and must be > 0 for hire purchase",
110
+ path: ["installmentCount"],
111
+ });
112
+ }
113
+ // Grace period days is required for hire purchase
114
+ if (data.gracePeriodDays === undefined) {
115
+ ctx.addIssue({
116
+ code: zod_1.z.ZodIssueCode.custom,
117
+ message: "Grace period days is required for hire purchase",
118
+ path: ["gracePeriodDays"],
119
+ });
120
+ }
121
+ // Auto lock on miss is required for hire purchase
122
+ if (data.autoLockOnMiss === undefined) {
123
+ ctx.addIssue({
124
+ code: zod_1.z.ZodIssueCode.custom,
125
+ message: "Auto lock on miss is required for hire purchase",
126
+ path: ["autoLockOnMiss"],
127
+ });
128
+ }
129
+ // Validate math: totalAmount = downPayment + (installmentAmount × installmentCount)
130
+ if (data.installmentAmount && data.installmentCount) {
131
+ const calculatedTotal = (data.downPayment || 0) +
132
+ data.installmentAmount * data.installmentCount;
133
+ if (Math.abs(calculatedTotal - data.totalAmount) > 0.01) {
134
+ ctx.addIssue({
135
+ code: zod_1.z.ZodIssueCode.custom,
136
+ message: `Total amount must equal downPayment + (installmentAmount × installmentCount). Expected ~${calculatedTotal.toFixed(2)}`,
137
+ path: ["totalAmount"],
138
+ });
139
+ }
140
+ }
141
+ // Down payment must be less than total amount
142
+ if (data.downPayment && data.downPayment >= data.totalAmount) {
143
+ ctx.addIssue({
144
+ code: zod_1.z.ZodIssueCode.custom,
145
+ message: "Down payment must be less than total amount",
146
+ path: ["downPayment"],
147
+ });
148
+ }
149
+ }
150
+ // FULL_PAYMENT validation - STRICT: ONLY totalAmount allowed!
151
+ if (data.type === "FULL_PAYMENT") {
152
+ // NO down payment allowed
153
+ if (data.downPayment !== undefined && data.downPayment > 0) {
154
+ ctx.addIssue({
155
+ code: zod_1.z.ZodIssueCode.custom,
156
+ message: "Down payment cannot be set for full payment. Use totalAmount only.",
157
+ path: ["downPayment"],
158
+ });
159
+ }
160
+ // NO installment amount allowed
161
+ if (data.installmentAmount !== undefined &&
162
+ data.installmentAmount !== null) {
163
+ ctx.addIssue({
164
+ code: zod_1.z.ZodIssueCode.custom,
165
+ message: "Installment amount cannot be set for full payment",
166
+ path: ["installmentAmount"],
167
+ });
168
+ }
169
+ // NO installment frequency allowed
170
+ if (data.installmentFrequency !== undefined &&
171
+ data.installmentFrequency !== null) {
172
+ ctx.addIssue({
173
+ code: zod_1.z.ZodIssueCode.custom,
174
+ message: "Installment frequency cannot be set for full payment",
175
+ path: ["installmentFrequency"],
176
+ });
177
+ }
178
+ // NO installment count allowed
179
+ if (data.installmentCount !== undefined &&
180
+ data.installmentCount !== null) {
181
+ ctx.addIssue({
182
+ code: zod_1.z.ZodIssueCode.custom,
183
+ message: "Installment count cannot be set for full payment",
184
+ path: ["installmentCount"],
185
+ });
186
+ }
187
+ // NO grace period days needed for full payment
188
+ if (data.gracePeriodDays !== undefined) {
189
+ ctx.addIssue({
190
+ code: zod_1.z.ZodIssueCode.custom,
191
+ message: "Grace period days is not applicable for full payment",
192
+ path: ["gracePeriodDays"],
193
+ });
194
+ }
195
+ // NO auto lock on miss needed for full payment
196
+ if (data.autoLockOnMiss !== undefined) {
197
+ ctx.addIssue({
198
+ code: zod_1.z.ZodIssueCode.custom,
199
+ message: "Auto lock on miss is not applicable for full payment",
200
+ path: ["autoLockOnMiss"],
201
+ });
202
+ }
203
+ // Total amount is required and must be positive
204
+ if (!data.totalAmount || data.totalAmount <= 0) {
205
+ ctx.addIssue({
206
+ code: zod_1.z.ZodIssueCode.custom,
207
+ message: "Total amount is required and must be > 0 for full payment",
208
+ path: ["totalAmount"],
209
+ });
210
+ }
211
+ }
212
+ }),
213
+ });
214
+ // Update pricing schema with STRICT validation
215
+ exports.updatePricingSchema = zod_1.z.object({
216
+ params: zod_1.z.object({
217
+ id: zod_1.z.string().uuid("Invalid pricing ID"),
218
+ }),
219
+ body: zod_1.z
220
+ .object({
221
+ name: pricingBaseSchema.name.optional(),
222
+ type: pricingBaseSchema.type.optional(),
223
+ totalAmount: pricingBaseSchema.totalAmount.optional(),
224
+ downPayment: pricingBaseSchema.downPayment.optional(),
225
+ installmentAmount: pricingBaseSchema.installmentAmount,
226
+ installmentFrequency: pricingBaseSchema.installmentFrequency,
227
+ installmentCount: pricingBaseSchema.installmentCount,
228
+ gracePeriodDays: pricingBaseSchema.gracePeriodDays.optional(),
229
+ autoLockOnMiss: pricingBaseSchema.autoLockOnMiss.optional(),
230
+ minOrderQuantity: pricingBaseSchema.minOrderQuantity.optional(),
231
+ maxOrderQuantity: pricingBaseSchema.maxOrderQuantity.optional(),
232
+ isActive: pricingBaseSchema.isActive.optional(),
233
+ })
234
+ .superRefine((data, ctx) => {
235
+ // Validate minOrderQuantity <= maxOrderQuantity if both are provided
236
+ if (data.minOrderQuantity !== undefined &&
237
+ data.maxOrderQuantity !== undefined) {
238
+ if (data.minOrderQuantity > data.maxOrderQuantity) {
239
+ ctx.addIssue({
240
+ code: zod_1.z.ZodIssueCode.custom,
241
+ message: "Minimum order quantity cannot be greater than maximum order quantity",
242
+ path: ["minOrderQuantity"],
243
+ });
244
+ }
245
+ }
246
+ // If type is being updated to HIRE_PURCHASE
247
+ if (data.type === "HIRE_PURCHASE") {
248
+ if (data.downPayment === undefined) {
249
+ ctx.addIssue({
250
+ code: zod_1.z.ZodIssueCode.custom,
251
+ message: "Down payment is required when updating to hire purchase",
252
+ path: ["downPayment"],
253
+ });
254
+ }
255
+ if (!data.installmentAmount) {
256
+ ctx.addIssue({
257
+ code: zod_1.z.ZodIssueCode.custom,
258
+ message: "Installment amount is required when updating to hire purchase",
259
+ path: ["installmentAmount"],
260
+ });
261
+ }
262
+ if (!data.installmentFrequency) {
263
+ ctx.addIssue({
264
+ code: zod_1.z.ZodIssueCode.custom,
265
+ message: "Installment frequency is required when updating to hire purchase",
266
+ path: ["installmentFrequency"],
267
+ });
268
+ }
269
+ if (!data.installmentCount) {
270
+ ctx.addIssue({
271
+ code: zod_1.z.ZodIssueCode.custom,
272
+ message: "Installment count is required when updating to hire purchase",
273
+ path: ["installmentCount"],
274
+ });
275
+ }
276
+ if (data.gracePeriodDays === undefined) {
277
+ ctx.addIssue({
278
+ code: zod_1.z.ZodIssueCode.custom,
279
+ message: "Grace period days is required for hire purchase",
280
+ path: ["gracePeriodDays"],
281
+ });
282
+ }
283
+ if (data.autoLockOnMiss === undefined) {
284
+ ctx.addIssue({
285
+ code: zod_1.z.ZodIssueCode.custom,
286
+ message: "Auto lock on miss is required for hire purchase",
287
+ path: ["autoLockOnMiss"],
288
+ });
289
+ }
290
+ }
291
+ // If type is being updated to FULL_PAYMENT - STRICT: NO extra fields!
292
+ if (data.type === "FULL_PAYMENT") {
293
+ if (data.downPayment !== undefined && data.downPayment > 0) {
294
+ ctx.addIssue({
295
+ code: zod_1.z.ZodIssueCode.custom,
296
+ message: "Down payment cannot be set for full payment",
297
+ path: ["downPayment"],
298
+ });
299
+ }
300
+ if (data.installmentAmount !== undefined &&
301
+ data.installmentAmount !== null) {
302
+ ctx.addIssue({
303
+ code: zod_1.z.ZodIssueCode.custom,
304
+ message: "Installment amount cannot be set for full payment",
305
+ path: ["installmentAmount"],
306
+ });
307
+ }
308
+ if (data.installmentFrequency !== undefined &&
309
+ data.installmentFrequency !== null) {
310
+ ctx.addIssue({
311
+ code: zod_1.z.ZodIssueCode.custom,
312
+ message: "Installment frequency cannot be set for full payment",
313
+ path: ["installmentFrequency"],
314
+ });
315
+ }
316
+ if (data.installmentCount !== undefined &&
317
+ data.installmentCount !== null) {
318
+ ctx.addIssue({
319
+ code: zod_1.z.ZodIssueCode.custom,
320
+ message: "Installment count cannot be set for full payment",
321
+ path: ["installmentCount"],
322
+ });
323
+ }
324
+ if (data.gracePeriodDays !== undefined) {
325
+ ctx.addIssue({
326
+ code: zod_1.z.ZodIssueCode.custom,
327
+ message: "Grace period days is not applicable for full payment",
328
+ path: ["gracePeriodDays"],
329
+ });
330
+ }
331
+ if (data.autoLockOnMiss !== undefined) {
332
+ ctx.addIssue({
333
+ code: zod_1.z.ZodIssueCode.custom,
334
+ message: "Auto lock on miss is not applicable for full payment",
335
+ path: ["autoLockOnMiss"],
336
+ });
337
+ }
338
+ }
339
+ if (!data.type && data.installmentAmount) {
340
+ ctx.addIssue({
341
+ code: zod_1.z.ZodIssueCode.custom,
342
+ message: "Cannot add installment fields to existing pricing without changing type to HIRE_PURCHASE",
343
+ path: ["installmentAmount"],
344
+ });
345
+ }
346
+ }),
347
+ });
348
+ // Get pricing by ID schema
349
+ exports.getPricingSchema = zod_1.z.object({
350
+ params: zod_1.z.object({
351
+ id: zod_1.z.string().uuid("Invalid pricing ID"),
352
+ }),
353
+ });
354
+ // Get all pricings schema
355
+ exports.getPricingsSchema = zod_1.z.object({
356
+ query: zod_1.z.object({
357
+ page: zod_1.z.string().regex(/^\d+$/).transform(Number).optional(),
358
+ limit: zod_1.z.string().regex(/^\d+$/).transform(Number).optional(),
359
+ productId: zod_1.z.string().uuid().optional(),
360
+ type: zod_1.z.enum(PRICING_TYPES).optional(),
361
+ isActive: zod_1.z.enum(["true", "false"]).optional(),
362
+ minAmount: zod_1.z.string().regex(/^\d+$/).transform(Number).optional(),
363
+ maxAmount: zod_1.z.string().regex(/^\d+$/).transform(Number).optional(),
364
+ search: zod_1.z.string().optional(),
365
+ sortBy: zod_1.z
366
+ .enum(["name", "totalAmount", "createdAt", "updatedAt"])
367
+ .optional(),
368
+ sortOrder: zod_1.z.enum(["ASC", "DESC"]).optional(),
369
+ }),
370
+ });
371
+ // Delete pricing schema
372
+ exports.deletePricingSchema = zod_1.z.object({
373
+ params: zod_1.z.object({
374
+ id: zod_1.z.string().uuid("Invalid pricing ID"),
375
+ }),
376
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-commons",
3
- "version": "1.0.94",
3
+ "version": "1.0.96",
4
4
  "description": "Shared functions package",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -103,7 +103,7 @@
103
103
  "rimraf": "^5.0.5",
104
104
  "streamifier": "^0.1.1",
105
105
  "typescript": "^5.3.3",
106
- "vr-models": "^1.0.51",
106
+ "vr-models": "^1.0.52",
107
107
  "zod": "^3.25.20"
108
108
  },
109
109
  "dependencies": {