vr-commons 1.0.24 → 1.0.26
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/utils/index.d.ts +1 -1
- package/dist/utils/index.js +24 -10
- package/dist/utils/profiles.utils.d.ts +193 -34
- package/dist/utils/profiles.utils.js +439 -132
- package/dist/validations/auth.validations.d.ts +42 -3
- package/dist/validations/auth.validations.js +15 -4
- package/dist/validations/index.d.ts +2 -2
- package/dist/validations/index.js +16 -3
- package/dist/validations/profiles.validations.d.ts +362 -75
- package/dist/validations/profiles.validations.js +202 -25
- package/package.json +1 -1
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.deleteAccountSchema = exports.deactivateAccountSchema = exports.changePasswordSchema = exports.getRiderProfileSchema = exports.updatePassengerProfileSchema = exports.passengerSignupSchema = exports.viewProfileSchema = exports.getAllUsersSchema = exports.updateUserProfileSchema = exports.getUserByIdSchema = exports.createUserSchema = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
|
-
//
|
|
5
|
+
// ============================================================================
|
|
6
|
+
// COMMON VALIDATIONS
|
|
7
|
+
// ============================================================================
|
|
6
8
|
const phoneNumberRegex = /^(078|079|072|073)\d{7}$/;
|
|
7
9
|
const nationalIdRegex = /^\d{16}$/;
|
|
8
|
-
|
|
10
|
+
const jacketIdRegex = /^JKT-\d{9}$/;
|
|
11
|
+
// ============================================================================
|
|
12
|
+
// ADMIN/SUPER ADMIN SCHEMAS
|
|
13
|
+
// ============================================================================
|
|
14
|
+
// Create User Schema (for admins creating agents/riders)
|
|
9
15
|
exports.createUserSchema = zod_1.z.object({
|
|
10
16
|
body: zod_1.z.object({
|
|
11
17
|
firstName: zod_1.z
|
|
@@ -32,17 +38,20 @@ exports.createUserSchema = zod_1.z.object({
|
|
|
32
38
|
.string()
|
|
33
39
|
.min(6, "Password must be at least 6 characters")
|
|
34
40
|
.max(100, "Password cannot exceed 100 characters"),
|
|
35
|
-
role: zod_1.z.enum(["AGENT", "RIDER"], {
|
|
36
|
-
errorMap: () => ({ message: "
|
|
41
|
+
role: zod_1.z.enum(["AGENT", "RIDER", "PASSENGER", "ADMIN", "SUPER_ADMIN"], {
|
|
42
|
+
errorMap: () => ({ message: "Invalid role specified" }),
|
|
37
43
|
}),
|
|
38
44
|
plateNumber: zod_1.z
|
|
39
45
|
.string()
|
|
40
46
|
.max(20, "Plate number cannot exceed 20 characters")
|
|
41
47
|
.optional()
|
|
42
48
|
.nullable(),
|
|
49
|
+
jacketId: zod_1.z
|
|
50
|
+
.string()
|
|
51
|
+
.regex(jacketIdRegex, "Jacket ID must be in format JKT-000000000")
|
|
52
|
+
.optional()
|
|
53
|
+
.nullable(),
|
|
43
54
|
}),
|
|
44
|
-
params: zod_1.z.object({}).optional(),
|
|
45
|
-
query: zod_1.z.object({}).optional(),
|
|
46
55
|
headers: zod_1.z.object({
|
|
47
56
|
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
48
57
|
message: "Authorization header must start with 'Bearer '",
|
|
@@ -54,26 +63,13 @@ exports.getUserByIdSchema = zod_1.z.object({
|
|
|
54
63
|
params: zod_1.z.object({
|
|
55
64
|
userId: zod_1.z.string().uuid("Invalid user ID format"),
|
|
56
65
|
}),
|
|
57
|
-
body: zod_1.z.object({}).optional(),
|
|
58
|
-
query: zod_1.z.object({}).optional(),
|
|
59
66
|
headers: zod_1.z.object({
|
|
60
67
|
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
61
68
|
message: "Authorization header must start with 'Bearer '",
|
|
62
69
|
}),
|
|
63
70
|
}),
|
|
64
71
|
});
|
|
65
|
-
//
|
|
66
|
-
exports.getAdminProfileSchema = zod_1.z.object({
|
|
67
|
-
params: zod_1.z.object({}).optional(),
|
|
68
|
-
body: zod_1.z.object({}).optional(),
|
|
69
|
-
query: zod_1.z.object({}).optional(),
|
|
70
|
-
headers: zod_1.z.object({
|
|
71
|
-
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
72
|
-
message: "Authorization header must start with 'Bearer '",
|
|
73
|
-
}),
|
|
74
|
-
}),
|
|
75
|
-
});
|
|
76
|
-
// Update User Profile Schema
|
|
72
|
+
// Update User Profile Schema (admin update)
|
|
77
73
|
exports.updateUserProfileSchema = zod_1.z.object({
|
|
78
74
|
params: zod_1.z.object({
|
|
79
75
|
userId: zod_1.z.string().uuid("Invalid user ID format"),
|
|
@@ -96,6 +92,10 @@ exports.updateUserProfileSchema = zod_1.z.object({
|
|
|
96
92
|
.optional()
|
|
97
93
|
.nullable()
|
|
98
94
|
.or(zod_1.z.literal("")),
|
|
95
|
+
phoneNumber: zod_1.z
|
|
96
|
+
.string()
|
|
97
|
+
.regex(phoneNumberRegex, "Invalid phone number format")
|
|
98
|
+
.optional(),
|
|
99
99
|
plateNumber: zod_1.z
|
|
100
100
|
.string()
|
|
101
101
|
.max(20, "Plate number cannot exceed 20 characters")
|
|
@@ -103,6 +103,7 @@ exports.updateUserProfileSchema = zod_1.z.object({
|
|
|
103
103
|
.nullable(),
|
|
104
104
|
isActive: zod_1.z.boolean().optional(),
|
|
105
105
|
isSuspended: zod_1.z.boolean().optional(),
|
|
106
|
+
isDeactivated: zod_1.z.boolean().optional(),
|
|
106
107
|
password: zod_1.z
|
|
107
108
|
.string()
|
|
108
109
|
.min(6, "Password must be at least 6 characters")
|
|
@@ -112,7 +113,6 @@ exports.updateUserProfileSchema = zod_1.z.object({
|
|
|
112
113
|
.refine((data) => Object.keys(data).length > 0, {
|
|
113
114
|
message: "At least one field must be provided for update",
|
|
114
115
|
}),
|
|
115
|
-
query: zod_1.z.object({}).optional(),
|
|
116
116
|
headers: zod_1.z.object({
|
|
117
117
|
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
118
118
|
message: "Authorization header must start with 'Bearer '",
|
|
@@ -121,17 +121,194 @@ exports.updateUserProfileSchema = zod_1.z.object({
|
|
|
121
121
|
});
|
|
122
122
|
// Get All Users Schema (with pagination/filtering)
|
|
123
123
|
exports.getAllUsersSchema = zod_1.z.object({
|
|
124
|
-
params: zod_1.z.object({}).optional(),
|
|
125
|
-
body: zod_1.z.object({}).optional(),
|
|
126
124
|
query: zod_1.z.object({
|
|
127
125
|
page: zod_1.z.string().regex(/^\d+$/).default("1").transform(Number).optional(),
|
|
128
126
|
limit: zod_1.z.string().regex(/^\d+$/).default("20").transform(Number).optional(),
|
|
129
|
-
role: zod_1.z
|
|
127
|
+
role: zod_1.z
|
|
128
|
+
.enum(["RIDER", "PASSENGER", "AGENT", "ADMIN", "SUPER_ADMIN"])
|
|
129
|
+
.optional(),
|
|
130
130
|
isActive: zod_1.z
|
|
131
131
|
.enum(["true", "false"])
|
|
132
132
|
.transform((val) => val === "true")
|
|
133
133
|
.optional(),
|
|
134
|
+
isSuspended: zod_1.z
|
|
135
|
+
.enum(["true", "false"])
|
|
136
|
+
.transform((val) => val === "true")
|
|
137
|
+
.optional(),
|
|
138
|
+
isBanned: zod_1.z
|
|
139
|
+
.enum(["true", "false"])
|
|
140
|
+
.transform((val) => val === "true")
|
|
141
|
+
.optional(),
|
|
134
142
|
search: zod_1.z.string().optional(),
|
|
143
|
+
startDate: zod_1.z.string().optional(),
|
|
144
|
+
endDate: zod_1.z.string().optional(),
|
|
145
|
+
sortBy: zod_1.z
|
|
146
|
+
.enum(["firstName", "lastLoginAt", "createdAt"])
|
|
147
|
+
.default("createdAt"),
|
|
148
|
+
order: zod_1.z.enum(["asc", "desc"]).default("desc"),
|
|
149
|
+
}),
|
|
150
|
+
headers: zod_1.z.object({
|
|
151
|
+
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
152
|
+
message: "Authorization header must start with 'Bearer '",
|
|
153
|
+
}),
|
|
154
|
+
}),
|
|
155
|
+
});
|
|
156
|
+
// ============================================================================
|
|
157
|
+
// PROFILE VIEW SCHEMAS
|
|
158
|
+
// ============================================================================
|
|
159
|
+
// View Profile Schema (generic)
|
|
160
|
+
exports.viewProfileSchema = zod_1.z.object({
|
|
161
|
+
params: zod_1.z.object({}).optional(),
|
|
162
|
+
body: zod_1.z.object({}).optional(),
|
|
163
|
+
query: zod_1.z.object({}).optional(),
|
|
164
|
+
headers: zod_1.z.object({
|
|
165
|
+
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
166
|
+
message: "Authorization header must start with 'Bearer '",
|
|
167
|
+
}),
|
|
168
|
+
}),
|
|
169
|
+
});
|
|
170
|
+
// ============================================================================
|
|
171
|
+
// PASSENGER SCHEMAS
|
|
172
|
+
// ============================================================================
|
|
173
|
+
// Passenger Signup Schema
|
|
174
|
+
exports.passengerSignupSchema = zod_1.z.object({
|
|
175
|
+
body: zod_1.z.object({
|
|
176
|
+
firstName: zod_1.z
|
|
177
|
+
.string()
|
|
178
|
+
.min(2, "First name must be at least 2 characters")
|
|
179
|
+
.max(100, "First name cannot exceed 100 characters"),
|
|
180
|
+
lastName: zod_1.z
|
|
181
|
+
.string()
|
|
182
|
+
.min(2, "Last name must be at least 2 characters")
|
|
183
|
+
.max(100, "Last name cannot exceed 100 characters"),
|
|
184
|
+
phoneNumber: zod_1.z
|
|
185
|
+
.string()
|
|
186
|
+
.regex(phoneNumberRegex, "Phone number must be a valid Rwandan number (078/079/072/073) followed by 7 digits"),
|
|
187
|
+
nationalId: zod_1.z
|
|
188
|
+
.string()
|
|
189
|
+
.regex(nationalIdRegex, "National ID must be 16 digits"),
|
|
190
|
+
jacketId: zod_1.z
|
|
191
|
+
.string()
|
|
192
|
+
.regex(jacketIdRegex, "Jacket ID must be in format JKT-000000000")
|
|
193
|
+
.optional(),
|
|
194
|
+
email: zod_1.z
|
|
195
|
+
.string()
|
|
196
|
+
.email("Invalid email address")
|
|
197
|
+
.optional()
|
|
198
|
+
.nullable()
|
|
199
|
+
.or(zod_1.z.literal("")),
|
|
200
|
+
password: zod_1.z
|
|
201
|
+
.string()
|
|
202
|
+
.min(6, "Password must be at least 6 characters")
|
|
203
|
+
.max(100, "Password cannot exceed 100 characters")
|
|
204
|
+
.optional()
|
|
205
|
+
.nullable(),
|
|
206
|
+
plateNumber: zod_1.z
|
|
207
|
+
.string()
|
|
208
|
+
.max(20, "Plate number cannot exceed 20 characters")
|
|
209
|
+
.optional()
|
|
210
|
+
.nullable(),
|
|
211
|
+
}),
|
|
212
|
+
headers: zod_1.z.object({}).optional(),
|
|
213
|
+
});
|
|
214
|
+
// Update Passenger Profile Schema
|
|
215
|
+
exports.updatePassengerProfileSchema = zod_1.z.object({
|
|
216
|
+
params: zod_1.z.object({}).optional(),
|
|
217
|
+
body: zod_1.z
|
|
218
|
+
.object({
|
|
219
|
+
firstName: zod_1.z
|
|
220
|
+
.string()
|
|
221
|
+
.min(2, "First name must be at least 2 characters")
|
|
222
|
+
.max(100, "First name cannot exceed 100 characters")
|
|
223
|
+
.optional(),
|
|
224
|
+
lastName: zod_1.z
|
|
225
|
+
.string()
|
|
226
|
+
.min(2, "Last name must be at least 2 characters")
|
|
227
|
+
.max(100, "Last name cannot exceed 100 characters")
|
|
228
|
+
.optional(),
|
|
229
|
+
email: zod_1.z
|
|
230
|
+
.string()
|
|
231
|
+
.email("Invalid email address")
|
|
232
|
+
.optional()
|
|
233
|
+
.nullable()
|
|
234
|
+
.or(zod_1.z.literal("")),
|
|
235
|
+
plateNumber: zod_1.z
|
|
236
|
+
.string()
|
|
237
|
+
.max(20, "Plate number cannot exceed 20 characters")
|
|
238
|
+
.optional()
|
|
239
|
+
.nullable(),
|
|
240
|
+
})
|
|
241
|
+
.refine((data) => Object.keys(data).length > 0, {
|
|
242
|
+
message: "At least one field must be provided for update",
|
|
243
|
+
}),
|
|
244
|
+
headers: zod_1.z.object({
|
|
245
|
+
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
246
|
+
message: "Authorization header must start with 'Bearer '",
|
|
247
|
+
}),
|
|
248
|
+
}),
|
|
249
|
+
});
|
|
250
|
+
// ============================================================================
|
|
251
|
+
// RIDER SCHEMAS
|
|
252
|
+
// ============================================================================
|
|
253
|
+
// Get Rider Profile Schema
|
|
254
|
+
exports.getRiderProfileSchema = zod_1.z.object({
|
|
255
|
+
params: zod_1.z.object({}).optional(),
|
|
256
|
+
body: zod_1.z.object({}).optional(),
|
|
257
|
+
query: zod_1.z.object({}).optional(),
|
|
258
|
+
headers: zod_1.z.object({
|
|
259
|
+
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
260
|
+
message: "Authorization header must start with 'Bearer '",
|
|
261
|
+
}),
|
|
262
|
+
}),
|
|
263
|
+
});
|
|
264
|
+
// ============================================================================
|
|
265
|
+
// ACCOUNT MANAGEMENT SCHEMAS
|
|
266
|
+
// ============================================================================
|
|
267
|
+
// Change Password Schema
|
|
268
|
+
exports.changePasswordSchema = zod_1.z.object({
|
|
269
|
+
params: zod_1.z.object({}).optional(),
|
|
270
|
+
body: zod_1.z.object({
|
|
271
|
+
currentPassword: zod_1.z.string().min(1, "Current password is required"),
|
|
272
|
+
newPassword: zod_1.z
|
|
273
|
+
.string()
|
|
274
|
+
.min(6, "New password must be at least 6 characters")
|
|
275
|
+
.max(100, "New password cannot exceed 100 characters"),
|
|
276
|
+
}),
|
|
277
|
+
headers: zod_1.z.object({
|
|
278
|
+
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
279
|
+
message: "Authorization header must start with 'Bearer '",
|
|
280
|
+
}),
|
|
281
|
+
}),
|
|
282
|
+
});
|
|
283
|
+
// Deactivate Account Schema
|
|
284
|
+
exports.deactivateAccountSchema = zod_1.z.object({
|
|
285
|
+
params: zod_1.z.object({}).optional(),
|
|
286
|
+
body: zod_1.z.object({
|
|
287
|
+
confirm: zod_1.z.boolean().refine((val) => val === true, {
|
|
288
|
+
message: "You must confirm deactivation",
|
|
289
|
+
}),
|
|
290
|
+
reason: zod_1.z
|
|
291
|
+
.string()
|
|
292
|
+
.max(500, "Reason cannot exceed 500 characters")
|
|
293
|
+
.optional(),
|
|
294
|
+
}),
|
|
295
|
+
headers: zod_1.z.object({
|
|
296
|
+
authorization: zod_1.z.string().regex(/^Bearer /, {
|
|
297
|
+
message: "Authorization header must start with 'Bearer '",
|
|
298
|
+
}),
|
|
299
|
+
}),
|
|
300
|
+
});
|
|
301
|
+
// Delete Account Schema
|
|
302
|
+
exports.deleteAccountSchema = zod_1.z.object({
|
|
303
|
+
params: zod_1.z.object({}).optional(),
|
|
304
|
+
body: zod_1.z.object({
|
|
305
|
+
confirm: zod_1.z.boolean().refine((val) => val === true, {
|
|
306
|
+
message: "You must confirm deletion",
|
|
307
|
+
}),
|
|
308
|
+
reason: zod_1.z
|
|
309
|
+
.string()
|
|
310
|
+
.max(500, "Reason cannot exceed 500 characters")
|
|
311
|
+
.optional(),
|
|
135
312
|
}),
|
|
136
313
|
headers: zod_1.z.object({
|
|
137
314
|
authorization: zod_1.z.string().regex(/^Bearer /, {
|