vr-commons 1.0.128 → 1.0.130

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.
@@ -1,4 +1,3 @@
1
- import { Transaction } from "sequelize";
2
1
  import { Ban, Suspension } from "vr-models";
3
2
  export interface BanStatus {
4
3
  isBanned: boolean;
@@ -16,6 +15,10 @@ export declare const checkIsUserBannedOrSuspended: (userId: string) => Promise<{
16
15
  message?: string;
17
16
  details?: Ban | Suspension;
18
17
  }>;
18
+ /**
19
+ * Check if user has active dependencies that prevent deletion/update
20
+ * FIXED: Removed references to non-existent fields
21
+ */
19
22
  export declare const checkAccountDependencies: (userId: string, transaction?: any) => Promise<{
20
23
  hasDependencies: boolean;
21
24
  activeDevicePlans: number;
@@ -23,7 +26,10 @@ export declare const checkAccountDependencies: (userId: string, transaction?: an
23
26
  activeSubscriptions: number;
24
27
  messages: string[];
25
28
  }>;
26
- export declare const hasActiveDependencies: (userId: string, transaction?: Transaction) => Promise<boolean>;
29
+ /**
30
+ * Quick check for active dependencies (returns boolean)
31
+ */
32
+ export declare const hasActiveDependencies: (userId: string, transaction?: any) => Promise<boolean>;
27
33
  export declare const canUserBeModified: (userId: string, transaction?: any) => Promise<{
28
34
  allowed: boolean;
29
35
  message?: string;
@@ -75,42 +75,59 @@ const checkIsUserBannedOrSuspended = async (userId) => {
75
75
  }
76
76
  };
77
77
  exports.checkIsUserBannedOrSuspended = checkIsUserBannedOrSuspended;
78
+ // src/utils/dependency.utils.ts
79
+ /**
80
+ * Check if user has active dependencies that prevent deletion/update
81
+ * FIXED: Removed references to non-existent fields
82
+ */
78
83
  const checkAccountDependencies = async (userId, transaction) => {
79
84
  const messages = [];
80
85
  // 1. Check for active device payment plans
81
86
  const activeDevicePlans = await vr_models_1.DevicePaymentPlan.count({
82
87
  where: {
83
88
  userId,
84
- status: { [sequelize_1.Op.in]: ["ACTIVE", "DEFAULTED"] }, // Adjust based on your status enum
89
+ status: { [sequelize_1.Op.in]: ["ACTIVE", "DEFAULTED"] },
85
90
  },
86
91
  transaction,
87
92
  });
88
93
  if (activeDevicePlans > 0) {
89
- messages.push(`You have ${activeDevicePlans} active device payment plan(s)`);
94
+ messages.push(`User has ${activeDevicePlans} active device payment plan(s)`);
90
95
  }
91
96
  // 2. Check for pending payments
92
97
  const pendingPayments = await vr_models_1.Payment.count({
93
98
  where: {
94
99
  userId,
95
- status: "PENDING", // Adjust based on your status enum
100
+ status: "PENDING",
96
101
  },
97
102
  transaction,
98
103
  });
99
104
  if (pendingPayments > 0) {
100
- messages.push(`You have ${pendingPayments} pending payment(s)`);
105
+ messages.push(`User has ${pendingPayments} pending payment(s)`);
101
106
  }
102
- // 3. Add more checks as needed (subscriptions, etc.)
103
- const hasDependencies = activeDevicePlans > 0 || pendingPayments > 0;
107
+ // 3. Check for successful payments (optional - if you want to prevent deletion)
108
+ const successfulPayments = await vr_models_1.Payment.count({
109
+ where: {
110
+ userId,
111
+ status: "SUCCESSFUL",
112
+ },
113
+ transaction,
114
+ });
115
+ if (successfulPayments > 0) {
116
+ messages.push(`User has ${successfulPayments} successful payment(s)`);
117
+ }
118
+ const hasDependencies = activeDevicePlans > 0 || pendingPayments > 0 || successfulPayments > 0;
104
119
  return {
105
120
  hasDependencies,
106
121
  activeDevicePlans,
107
122
  pendingPayments,
108
- activeSubscriptions: 0, // Implement if needed
123
+ activeSubscriptions: 0,
109
124
  messages,
110
125
  };
111
126
  };
112
127
  exports.checkAccountDependencies = checkAccountDependencies;
113
- // Then update the hasActiveDependencies function in passengerUser.utils.ts:
128
+ /**
129
+ * Quick check for active dependencies (returns boolean)
130
+ */
114
131
  const hasActiveDependencies = async (userId, transaction) => {
115
132
  const result = await (0, exports.checkAccountDependencies)(userId, transaction);
116
133
  return result.hasDependencies;
@@ -91,6 +91,7 @@ export declare const JACKET_ID_REGEX: RegExp;
91
91
  export declare const JACKET_ID_PREFIX = "JKT";
92
92
  /**
93
93
  * Format user profile based on viewer type and options
94
+ * FIXED: Removed email and nationalId references
94
95
  */
95
96
  export declare const formatUserProfile: (user: User, viewerType?: UserType, options?: ProfileFormatOptions) => RiderProfile | PassengerProfile | AgentProfile | AdminProfile | SuperAdminProfile;
96
97
  /**
@@ -18,13 +18,17 @@ exports.JACKET_ID_PREFIX = "JKT";
18
18
  // ============================================================================
19
19
  /**
20
20
  * Format user profile based on viewer type and options
21
+ * FIXED: Removed email and nationalId references
21
22
  */
22
23
  const formatUserProfile = (user, viewerType = "ADMIN", options = {}) => {
24
+ // Get primary contact
25
+ const primaryContact = user.primaryContact ||
26
+ user.contacts?.find((c) => c.isPrimary === true);
23
27
  const baseProfile = {
24
28
  id: user.id,
25
29
  firstName: user.firstName,
26
30
  lastName: user.lastName,
27
- primaryContact: user.primaryContact?.contactValue,
31
+ primaryContact: primaryContact?.contactValue,
28
32
  gender: user.gender || "male",
29
33
  birthDate: user.birthDate || null,
30
34
  birthMonth: user.birthMonth || null,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vr-commons",
3
- "version": "1.0.128",
3
+ "version": "1.0.130",
4
4
  "description": "Shared functions package",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",