vr-commons 1.0.177 → 1.0.181

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.
@@ -7,7 +7,8 @@ export interface DeleteCheckResult {
7
7
  export declare const DPP_OperationsUtil: {
8
8
  /**
9
9
  * Check if a payment plan can be deleted
10
- * Rule: Can only delete if NO payments have been made
10
+ * Financial records are permanent: delete only plans with no payments and
11
+ * no installments of any status.
11
12
  */
12
13
  canDeletePlan(planId: string, transaction?: Transaction): Promise<DeleteCheckResult>;
13
14
  /**
@@ -5,7 +5,8 @@ const vr_models_1 = require("vr-models");
5
5
  exports.DPP_OperationsUtil = {
6
6
  /**
7
7
  * Check if a payment plan can be deleted
8
- * Rule: Can only delete if NO payments have been made
8
+ * Financial records are permanent: delete only plans with no payments and
9
+ * no installments of any status.
9
10
  */
10
11
  async canDeletePlan(planId, transaction) {
11
12
  // Check if any payments exist for this plan
@@ -19,18 +20,14 @@ exports.DPP_OperationsUtil = {
19
20
  reason: `Cannot delete plan with ${paymentCount} payment(s) already recorded`,
20
21
  };
21
22
  }
22
- // Also check if any installments are paid
23
- const paidInstallments = await vr_models_1.Installment.count({
24
- where: {
25
- devicePaymentPlanId: planId,
26
- status: "PAID",
27
- },
23
+ const installmentCount = await vr_models_1.Installment.count({
24
+ where: { devicePaymentPlanId: planId },
28
25
  transaction,
29
26
  });
30
- if (paidInstallments > 0) {
27
+ if (installmentCount > 0) {
31
28
  return {
32
29
  canDelete: false,
33
- reason: "Cannot delete plan with paid installments",
30
+ reason: `Cannot delete plan with ${installmentCount} installment(s) recorded`,
34
31
  };
35
32
  }
36
33
  return { canDelete: true };
@@ -157,6 +154,7 @@ exports.DPP_OperationsUtil = {
157
154
  const planData = {
158
155
  id: plan.id,
159
156
  userId: plan.userId,
157
+ productId: plan.productId,
160
158
  pricingSnapshot: plan.pricingSnapshot,
161
159
  totalAmount: plan.totalAmount, // ✅ Added
162
160
  paidAmount: plan.paidAmount,
@@ -177,6 +175,7 @@ exports.DPP_OperationsUtil = {
177
175
  return {
178
176
  id: planData.id,
179
177
  userId: planData.userId,
178
+ productId: planData.productId,
180
179
  pricingSnapshot: {
181
180
  id: planData.pricingSnapshot?.id || null,
182
181
  name: planData.pricingSnapshot?.name || null,
@@ -190,7 +189,12 @@ exports.DPP_OperationsUtil = {
190
189
  autoLockOnMiss: planData.pricingSnapshot?.autoLockOnMiss ?? true,
191
190
  minOrderQuantity: planData.pricingSnapshot?.minOrderQuantity || 1,
192
191
  maxOrderQuantity: planData.pricingSnapshot?.maxOrderQuantity || 1,
192
+ productId: planData.pricingSnapshot?.productId || planData.productId,
193
+ productName: planData.pricingSnapshot?.productName || null,
194
+ pairId: planData.pricingSnapshot?.pairId || null,
195
+ deviceIds: planData.pricingSnapshot?.deviceIds || [],
193
196
  },
197
+ historicalDeviceIds: planData.pricingSnapshot?.deviceIds || [],
194
198
  totalAmount: totalAmount, // ✅ Added
195
199
  paidAmount: planData.paidAmount || 0,
196
200
  outstandingAmount: planData.outstandingAmount || 0,
@@ -83,7 +83,7 @@ const sendSMS = async (phoneNumber, message) => {
83
83
  // from: fromNumber,
84
84
  // to: phoneNumber,
85
85
  // });
86
- console.log(`✅ SMS sent to ${phoneNumber}, ${message}`);
86
+ // Verification codes and full contact details must never be written to logs.
87
87
  return true;
88
88
  }
89
89
  catch (error) {
@@ -111,7 +111,7 @@ const sendEmail = async (to, subject, html) => {
111
111
  subject,
112
112
  html,
113
113
  });
114
- console.log(`✅ Email sent to ${to}`);
114
+ console.log("Verification email sent");
115
115
  return true;
116
116
  }
117
117
  catch (error) {
@@ -6,24 +6,24 @@ export declare const createPlanSchema: z.ZodObject<{
6
6
  productId: z.ZodString;
7
7
  }, "strip", z.ZodTypeAny, {
8
8
  userId: string;
9
- productId: string;
10
9
  pricingId: string;
10
+ productId: string;
11
11
  }, {
12
12
  userId: string;
13
- productId: string;
14
13
  pricingId: string;
14
+ productId: string;
15
15
  }>;
16
16
  }, "strip", z.ZodTypeAny, {
17
17
  body: {
18
18
  userId: string;
19
- productId: string;
20
19
  pricingId: string;
20
+ productId: string;
21
21
  };
22
22
  }, {
23
23
  body: {
24
24
  userId: string;
25
- productId: string;
26
25
  pricingId: string;
26
+ productId: string;
27
27
  };
28
28
  }>;
29
29
  export declare const listPlansSchema: z.ZodObject<{
@@ -38,49 +38,49 @@ export declare const listPlansSchema: z.ZodObject<{
38
38
  sortBy: z.ZodOptional<z.ZodEnum<["createdAt", "updatedAt", "nextInstallmentDueAt", "paidAmount", "outstandingAmount"]>>;
39
39
  sortOrder: z.ZodOptional<z.ZodEnum<["ASC", "DESC"]>>;
40
40
  }, "strip", z.ZodTypeAny, {
41
- limit: number;
42
41
  page: number;
43
- search?: string | undefined;
42
+ limit: number;
43
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
44
44
  userId?: string | undefined;
45
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
46
- isOverdue?: "true" | "false" | undefined;
47
- sortBy?: "createdAt" | "updatedAt" | "paidAmount" | "outstandingAmount" | "nextInstallmentDueAt" | undefined;
48
- sortOrder?: "DESC" | "ASC" | undefined;
49
45
  deviceId?: string | undefined;
50
- }, {
46
+ isOverdue?: "true" | "false" | undefined;
51
47
  search?: string | undefined;
52
- limit?: string | undefined;
48
+ sortBy?: "createdAt" | "updatedAt" | "nextInstallmentDueAt" | "paidAmount" | "outstandingAmount" | undefined;
49
+ sortOrder?: "ASC" | "DESC" | undefined;
50
+ }, {
51
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
53
52
  userId?: string | undefined;
54
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
55
- isOverdue?: "true" | "false" | undefined;
56
53
  page?: string | undefined;
57
- sortBy?: "createdAt" | "updatedAt" | "paidAmount" | "outstandingAmount" | "nextInstallmentDueAt" | undefined;
58
- sortOrder?: "DESC" | "ASC" | undefined;
54
+ limit?: string | undefined;
59
55
  deviceId?: string | undefined;
56
+ isOverdue?: "true" | "false" | undefined;
57
+ search?: string | undefined;
58
+ sortBy?: "createdAt" | "updatedAt" | "nextInstallmentDueAt" | "paidAmount" | "outstandingAmount" | undefined;
59
+ sortOrder?: "ASC" | "DESC" | undefined;
60
60
  }>;
61
61
  }, "strip", z.ZodTypeAny, {
62
62
  query: {
63
- limit: number;
64
63
  page: number;
65
- search?: string | undefined;
64
+ limit: number;
65
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
66
66
  userId?: string | undefined;
67
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
68
- isOverdue?: "true" | "false" | undefined;
69
- sortBy?: "createdAt" | "updatedAt" | "paidAmount" | "outstandingAmount" | "nextInstallmentDueAt" | undefined;
70
- sortOrder?: "DESC" | "ASC" | undefined;
71
67
  deviceId?: string | undefined;
68
+ isOverdue?: "true" | "false" | undefined;
69
+ search?: string | undefined;
70
+ sortBy?: "createdAt" | "updatedAt" | "nextInstallmentDueAt" | "paidAmount" | "outstandingAmount" | undefined;
71
+ sortOrder?: "ASC" | "DESC" | undefined;
72
72
  };
73
73
  }, {
74
74
  query: {
75
- search?: string | undefined;
76
- limit?: string | undefined;
75
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
77
76
  userId?: string | undefined;
78
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
79
- isOverdue?: "true" | "false" | undefined;
80
77
  page?: string | undefined;
81
- sortBy?: "createdAt" | "updatedAt" | "paidAmount" | "outstandingAmount" | "nextInstallmentDueAt" | undefined;
82
- sortOrder?: "DESC" | "ASC" | undefined;
78
+ limit?: string | undefined;
83
79
  deviceId?: string | undefined;
80
+ isOverdue?: "true" | "false" | undefined;
81
+ search?: string | undefined;
82
+ sortBy?: "createdAt" | "updatedAt" | "nextInstallmentDueAt" | "paidAmount" | "outstandingAmount" | undefined;
83
+ sortOrder?: "ASC" | "DESC" | undefined;
84
84
  };
85
85
  }>;
86
86
  export declare const getPlanSchema: z.ZodObject<{
@@ -112,10 +112,10 @@ export declare const getUserPlansSchema: z.ZodObject<{
112
112
  status: z.ZodOptional<z.ZodEnum<["PENDING", "ACTIVE", "COMPLETED", "DEFAULTED", "CANCELLED"]>>;
113
113
  includeCompleted: z.ZodOptional<z.ZodEnum<["true", "false"]>>;
114
114
  }, "strip", z.ZodTypeAny, {
115
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
115
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
116
116
  includeCompleted?: "true" | "false" | undefined;
117
117
  }, {
118
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
118
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
119
119
  includeCompleted?: "true" | "false" | undefined;
120
120
  }>>;
121
121
  }, "strip", z.ZodTypeAny, {
@@ -123,7 +123,7 @@ export declare const getUserPlansSchema: z.ZodObject<{
123
123
  userId: string;
124
124
  };
125
125
  query?: {
126
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
126
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
127
127
  includeCompleted?: "true" | "false" | undefined;
128
128
  } | undefined;
129
129
  }, {
@@ -131,7 +131,7 @@ export declare const getUserPlansSchema: z.ZodObject<{
131
131
  userId: string;
132
132
  };
133
133
  query?: {
134
- status?: "ACTIVE" | "DEFAULTED" | "PENDING" | "COMPLETED" | "CANCELLED" | undefined;
134
+ status?: "PENDING" | "ACTIVE" | "COMPLETED" | "DEFAULTED" | "CANCELLED" | undefined;
135
135
  includeCompleted?: "true" | "false" | undefined;
136
136
  } | undefined;
137
137
  }>;
@@ -152,6 +152,41 @@ export declare const getDevicePlanSchema: z.ZodObject<{
152
152
  deviceId: string;
153
153
  };
154
154
  }>;
155
+ export declare const replacePlanDevicesSchema: z.ZodObject<{
156
+ params: z.ZodObject<{
157
+ id: z.ZodString;
158
+ }, "strip", z.ZodTypeAny, {
159
+ id: string;
160
+ }, {
161
+ id: string;
162
+ }>;
163
+ body: z.ZodObject<{
164
+ replacementPrefix: z.ZodEnum<["VBRD", "VIBERIDE"]>;
165
+ replacementPairID: z.ZodString;
166
+ }, "strip", z.ZodTypeAny, {
167
+ replacementPrefix: "VBRD" | "VIBERIDE";
168
+ replacementPairID: string;
169
+ }, {
170
+ replacementPrefix: "VBRD" | "VIBERIDE";
171
+ replacementPairID: string;
172
+ }>;
173
+ }, "strip", z.ZodTypeAny, {
174
+ params: {
175
+ id: string;
176
+ };
177
+ body: {
178
+ replacementPrefix: "VBRD" | "VIBERIDE";
179
+ replacementPairID: string;
180
+ };
181
+ }, {
182
+ params: {
183
+ id: string;
184
+ };
185
+ body: {
186
+ replacementPrefix: "VBRD" | "VIBERIDE";
187
+ replacementPairID: string;
188
+ };
189
+ }>;
155
190
  export declare const limitedUpdateSchema: z.ZodObject<{
156
191
  params: z.ZodObject<{
157
192
  id: z.ZodString;
@@ -166,38 +201,38 @@ export declare const limitedUpdateSchema: z.ZodObject<{
166
201
  userId: z.ZodOptional<z.ZodString>;
167
202
  }, "strip", z.ZodTypeAny, {
168
203
  userId?: string | undefined;
169
- productId?: string | undefined;
170
204
  pricingId?: string | undefined;
205
+ productId?: string | undefined;
171
206
  }, {
172
207
  userId?: string | undefined;
173
- productId?: string | undefined;
174
208
  pricingId?: string | undefined;
209
+ productId?: string | undefined;
175
210
  }>, {
176
211
  userId?: string | undefined;
177
- productId?: string | undefined;
178
212
  pricingId?: string | undefined;
213
+ productId?: string | undefined;
179
214
  }, {
180
215
  userId?: string | undefined;
181
- productId?: string | undefined;
182
216
  pricingId?: string | undefined;
217
+ productId?: string | undefined;
183
218
  }>;
184
219
  }, "strip", z.ZodTypeAny, {
220
+ params: {
221
+ id: string;
222
+ };
185
223
  body: {
186
224
  userId?: string | undefined;
187
- productId?: string | undefined;
188
225
  pricingId?: string | undefined;
226
+ productId?: string | undefined;
189
227
  };
228
+ }, {
190
229
  params: {
191
230
  id: string;
192
231
  };
193
- }, {
194
232
  body: {
195
233
  userId?: string | undefined;
196
- productId?: string | undefined;
197
234
  pricingId?: string | undefined;
198
- };
199
- params: {
200
- id: string;
235
+ productId?: string | undefined;
201
236
  };
202
237
  }>;
203
238
  export declare const recordPaymentSchema: z.ZodObject<{
@@ -211,7 +246,7 @@ export declare const recordPaymentSchema: z.ZodObject<{
211
246
  body: z.ZodObject<{
212
247
  amount: z.ZodNumber;
213
248
  provider: z.ZodDefault<z.ZodEnum<["AIRTEL_MONEY", "CASH", "MOMO_PAY"]>>;
214
- providerReference: z.ZodOptional<z.ZodString>;
249
+ providerReference: z.ZodString;
215
250
  customerPhone: z.ZodOptional<z.ZodString>;
216
251
  customerName: z.ZodOptional<z.ZodString>;
217
252
  notes: z.ZodOptional<z.ZodString>;
@@ -219,45 +254,45 @@ export declare const recordPaymentSchema: z.ZodObject<{
219
254
  }, "strip", z.ZodTypeAny, {
220
255
  amount: number;
221
256
  provider: "AIRTEL_MONEY" | "CASH" | "MOMO_PAY";
222
- metadata?: Record<string, any> | undefined;
223
- providerReference?: string | undefined;
257
+ providerReference: string;
224
258
  customerPhone?: string | undefined;
225
259
  customerName?: string | undefined;
226
260
  notes?: string | undefined;
261
+ metadata?: Record<string, any> | undefined;
227
262
  }, {
228
263
  amount: number;
229
- metadata?: Record<string, any> | undefined;
264
+ providerReference: string;
230
265
  provider?: "AIRTEL_MONEY" | "CASH" | "MOMO_PAY" | undefined;
231
- providerReference?: string | undefined;
232
266
  customerPhone?: string | undefined;
233
267
  customerName?: string | undefined;
234
268
  notes?: string | undefined;
269
+ metadata?: Record<string, any> | undefined;
235
270
  }>;
236
271
  }, "strip", z.ZodTypeAny, {
272
+ params: {
273
+ id: string;
274
+ };
237
275
  body: {
238
276
  amount: number;
239
277
  provider: "AIRTEL_MONEY" | "CASH" | "MOMO_PAY";
240
- metadata?: Record<string, any> | undefined;
241
- providerReference?: string | undefined;
278
+ providerReference: string;
242
279
  customerPhone?: string | undefined;
243
280
  customerName?: string | undefined;
244
281
  notes?: string | undefined;
282
+ metadata?: Record<string, any> | undefined;
245
283
  };
284
+ }, {
246
285
  params: {
247
286
  id: string;
248
287
  };
249
- }, {
250
288
  body: {
251
289
  amount: number;
252
- metadata?: Record<string, any> | undefined;
290
+ providerReference: string;
253
291
  provider?: "AIRTEL_MONEY" | "CASH" | "MOMO_PAY" | undefined;
254
- providerReference?: string | undefined;
255
292
  customerPhone?: string | undefined;
256
293
  customerName?: string | undefined;
257
294
  notes?: string | undefined;
258
- };
259
- params: {
260
- id: string;
295
+ metadata?: Record<string, any> | undefined;
261
296
  };
262
297
  }>;
263
298
  export declare const deletePlanSchema: z.ZodObject<{
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.deletePlanSchema = exports.recordPaymentSchema = exports.limitedUpdateSchema = exports.getDevicePlanSchema = exports.getUserPlansSchema = exports.getPlanSchema = exports.listPlansSchema = exports.createPlanSchema = void 0;
3
+ exports.deletePlanSchema = exports.recordPaymentSchema = exports.limitedUpdateSchema = exports.replacePlanDevicesSchema = exports.getDevicePlanSchema = exports.getUserPlansSchema = exports.getPlanSchema = exports.listPlansSchema = exports.createPlanSchema = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const vr_models_1 = require("vr-models");
6
6
  const regex_constants_1 = require("../../constants/regex.constants");
@@ -55,6 +55,18 @@ exports.getDevicePlanSchema = zod_1.z.object({
55
55
  deviceId: zod_1.z.string().uuid("Invalid device ID"),
56
56
  }),
57
57
  });
58
+ // ==================== DEVICE REPLACEMENT ====================
59
+ exports.replacePlanDevicesSchema = zod_1.z.object({
60
+ params: zod_1.z.object({
61
+ id: zod_1.z.string().uuid("Invalid payment plan ID"),
62
+ }),
63
+ body: zod_1.z.object({
64
+ replacementPrefix: zod_1.z.enum(["VBRD", "VIBERIDE"]),
65
+ replacementPairID: zod_1.z
66
+ .string()
67
+ .regex(regex_constants_1.DEVICE_PAIR_ID_REGEX, "Invalid pair ID format"),
68
+ }),
69
+ });
58
70
  // ==================== UPDATE ====================
59
71
  // validations/operations.validation.ts
60
72
  exports.limitedUpdateSchema = zod_1.z.object({
@@ -79,7 +91,7 @@ exports.recordPaymentSchema = zod_1.z.object({
79
91
  body: zod_1.z.object({
80
92
  amount: zod_1.z.number().min(0.01, "Amount must be greater than 0"),
81
93
  provider: zod_1.z.enum(vr_models_1.PAYMENT_PROVIDER).default("MOMO_PAY"),
82
- providerReference: zod_1.z.string().optional(),
94
+ providerReference: zod_1.z.string().trim().min(1).max(255),
83
95
  customerPhone: zod_1.z
84
96
  .string()
85
97
  .regex(/^\+?250[0-9]{9}$/, "Invalid MTN Rwanda phone number")