@servemate/dto 1.0.0

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.
@@ -0,0 +1,411 @@
1
+ import { z } from 'zod';
2
+ import { UserRole } from './enums';
3
+ /**
4
+ * User-related constants
5
+ */
6
+ export declare const UserSortColumn: {
7
+ readonly ID: "id";
8
+ readonly NAME: "name";
9
+ readonly EMAIL: "email";
10
+ readonly ROLE: "role";
11
+ readonly CREATED_AT: "createdAt";
12
+ readonly UPDATED_AT: "updatedAt";
13
+ };
14
+ export type UserSortColumn = (typeof UserSortColumn)[keyof typeof UserSortColumn];
15
+ /**
16
+ *
17
+ * User schemas
18
+ */
19
+ /**
20
+ * Schema for a complete user object.
21
+ * This schema defines all the fields that a user can have in the system.
22
+ * It uses Zod for runtime type checking and validation.
23
+ */
24
+ export declare const UserSchema: z.ZodObject<{
25
+ id: z.ZodNumber;
26
+ name: z.ZodString;
27
+ email: z.ZodString;
28
+ role: z.ZodNativeEnum<{
29
+ readonly ADMIN: "ADMIN";
30
+ readonly USER: "USER";
31
+ readonly HOST: "HOST";
32
+ readonly MANAGER: "MANAGER";
33
+ }>;
34
+ isActive: z.ZodDefault<z.ZodBoolean>;
35
+ password: z.ZodString;
36
+ createdAt: z.ZodDefault<z.ZodDate>;
37
+ updatedAt: z.ZodDefault<z.ZodDate>;
38
+ lastLogin: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
39
+ }, "strip", z.ZodTypeAny, {
40
+ id: number;
41
+ name: string;
42
+ createdAt: Date;
43
+ updatedAt: Date;
44
+ email: string;
45
+ role: "ADMIN" | "USER" | "HOST" | "MANAGER";
46
+ isActive: boolean;
47
+ password: string;
48
+ lastLogin?: Date | null | undefined;
49
+ }, {
50
+ id: number;
51
+ name: string;
52
+ email: string;
53
+ role: "ADMIN" | "USER" | "HOST" | "MANAGER";
54
+ password: string;
55
+ createdAt?: Date | undefined;
56
+ updatedAt?: Date | undefined;
57
+ isActive?: boolean | undefined;
58
+ lastLogin?: Date | null | undefined;
59
+ }>;
60
+ /**
61
+ * Schema for creating a new user.
62
+ * This schema picks specific fields from the UserSchema to ensure only necessary data is provided when creating a user.
63
+ *
64
+ * @remarks
65
+ * The schema includes the following fields:
66
+ * - name: The user's name
67
+ * - email: The user's email address
68
+ * - role: The user's role in the system
69
+ * - password: The user's password
70
+ *
71
+ * @returns A Zod schema object that can be used to validate data for creating a new user
72
+ */
73
+ export declare const CreateUserSchema: z.ZodObject<Pick<{
74
+ id: z.ZodNumber;
75
+ name: z.ZodString;
76
+ email: z.ZodString;
77
+ role: z.ZodNativeEnum<{
78
+ readonly ADMIN: "ADMIN";
79
+ readonly USER: "USER";
80
+ readonly HOST: "HOST";
81
+ readonly MANAGER: "MANAGER";
82
+ }>;
83
+ isActive: z.ZodDefault<z.ZodBoolean>;
84
+ password: z.ZodString;
85
+ createdAt: z.ZodDefault<z.ZodDate>;
86
+ updatedAt: z.ZodDefault<z.ZodDate>;
87
+ lastLogin: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
88
+ }, "name" | "email" | "role" | "password">, "strip", z.ZodTypeAny, {
89
+ name: string;
90
+ email: string;
91
+ role: "ADMIN" | "USER" | "HOST" | "MANAGER";
92
+ password: string;
93
+ }, {
94
+ name: string;
95
+ email: string;
96
+ role: "ADMIN" | "USER" | "HOST" | "MANAGER";
97
+ password: string;
98
+ }>;
99
+ /**
100
+ * Schema for a single ID parameter.
101
+ * Used when an API endpoint requires only an ID as input.
102
+ *
103
+ * @property {string} id - The unique identifier (non-empty string).
104
+ */
105
+ export declare const IdParamSchema: z.ZodObject<{
106
+ id: z.ZodString;
107
+ }, "strip", z.ZodTypeAny, {
108
+ id: string;
109
+ }, {
110
+ id: string;
111
+ }>;
112
+ /**
113
+ * Schema for user query parameters.
114
+ * This schema defines and validates the structure of query parameters used for searching, filtering, and sorting users.
115
+ *
116
+ * @param {object} params - The object containing user query parameters
117
+ * @param {string} [params.id] - The user's ID (optional, will be transformed to a number)
118
+ * @param {string} [params.email] - The user's email address (optional, must be a valid email)
119
+ * @param {string} [params.name] - The user's name (optional, minimum 3 characters)
120
+ * @param {string} [params.page] - The page number for pagination (optional, will be transformed to a number)
121
+ * @param {string} [params.pageSize] - The number of items per page (optional, will be transformed to a number)
122
+ * @param {UserSortColumn} [params.sortBy] - The column to sort by (optional, must be a valid UserSortColumn)
123
+ * @param {'asc' | 'desc'} [params.sortOrder] - The order to sort in (optional, 'asc' or 'desc')
124
+ * @param {string} [params.role] - The user's role (optional, will be transformed to uppercase and validated against Role enum)
125
+ * @param {boolean} [params.isActive] - The user's active status (optional)
126
+ * @param {string} [params.createdAfter] - The date after which users were created (optional, must be a valid date string)
127
+ * @param {string} [params.createdBefore] - The date before which users were created (optional, must be a valid date string)
128
+ *
129
+ * @returns {z.ZodObject} A Zod schema object that can be used to validate and transform user query parameters
130
+ */
131
+ export declare const UserParamSchema: z.ZodObject<{
132
+ id: z.ZodOptional<z.ZodNumber>;
133
+ email: z.ZodOptional<z.ZodOptional<z.ZodString>>;
134
+ name: z.ZodOptional<z.ZodOptional<z.ZodString>>;
135
+ page: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodString>, number | undefined, string | undefined>>;
136
+ pageSize: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodString>, number | undefined, string | undefined>>;
137
+ sortBy: z.ZodOptional<z.ZodOptional<z.ZodNativeEnum<{
138
+ readonly ID: "id";
139
+ readonly NAME: "name";
140
+ readonly EMAIL: "email";
141
+ readonly ROLE: "role";
142
+ readonly CREATED_AT: "createdAt";
143
+ readonly UPDATED_AT: "updatedAt";
144
+ }>>>;
145
+ sortOrder: z.ZodOptional<z.ZodOptional<z.ZodEnum<["asc", "desc"]>>>;
146
+ role: z.ZodOptional<z.ZodOptional<z.ZodPipeline<z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>, z.ZodNativeEnum<{
147
+ readonly ADMIN: "ADMIN";
148
+ readonly USER: "USER";
149
+ readonly HOST: "HOST";
150
+ readonly MANAGER: "MANAGER";
151
+ }>>>>;
152
+ isActive: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodEnum<["true", "false"]>>, boolean | undefined, "true" | "false" | undefined>>;
153
+ createdAfter: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>>;
154
+ createdBefore: z.ZodOptional<z.ZodEffects<z.ZodOptional<z.ZodString>, string | undefined, string | undefined>>;
155
+ }, "strip", z.ZodTypeAny, {
156
+ page?: number | undefined;
157
+ pageSize?: number | undefined;
158
+ sortOrder?: "asc" | "desc" | undefined;
159
+ id?: number | undefined;
160
+ name?: string | undefined;
161
+ sortBy?: "id" | "name" | "createdAt" | "updatedAt" | "email" | "role" | undefined;
162
+ email?: string | undefined;
163
+ role?: "ADMIN" | "USER" | "HOST" | "MANAGER" | undefined;
164
+ isActive?: boolean | undefined;
165
+ createdAfter?: string | undefined;
166
+ createdBefore?: string | undefined;
167
+ }, {
168
+ page?: string | undefined;
169
+ pageSize?: string | undefined;
170
+ sortOrder?: "asc" | "desc" | undefined;
171
+ id?: number | undefined;
172
+ name?: string | undefined;
173
+ sortBy?: "id" | "name" | "createdAt" | "updatedAt" | "email" | "role" | undefined;
174
+ email?: string | undefined;
175
+ role?: string | undefined;
176
+ isActive?: "true" | "false" | undefined;
177
+ createdAfter?: string | undefined;
178
+ createdBefore?: string | undefined;
179
+ }>;
180
+ /**
181
+ * Schema for updating user information.
182
+ * All fields are optional, but at least one must be provided.
183
+ *
184
+ * @property {string} [name] - The user's new name (optional, minimum 1 character).
185
+ * @property {string} [email] - The user's new email address (optional).
186
+ * @property {Role} [role] - The user's new role (optional).
187
+ * @property {boolean} [isActive] - The user's new active status (optional).
188
+ */
189
+ export declare const UpdateUserSchema: z.ZodEffects<z.ZodObject<{
190
+ name: z.ZodOptional<z.ZodString>;
191
+ email: z.ZodOptional<z.ZodString>;
192
+ role: z.ZodOptional<z.ZodNativeEnum<{
193
+ readonly ADMIN: "ADMIN";
194
+ readonly USER: "USER";
195
+ readonly HOST: "HOST";
196
+ readonly MANAGER: "MANAGER";
197
+ }>>;
198
+ isActive: z.ZodOptional<z.ZodDefault<z.ZodBoolean>>;
199
+ lastLogin: z.ZodOptional<z.ZodNullable<z.ZodOptional<z.ZodDate>>>;
200
+ }, "strip", z.ZodTypeAny, {
201
+ name?: string | undefined;
202
+ email?: string | undefined;
203
+ role?: "ADMIN" | "USER" | "HOST" | "MANAGER" | undefined;
204
+ isActive?: boolean | undefined;
205
+ lastLogin?: Date | null | undefined;
206
+ }, {
207
+ name?: string | undefined;
208
+ email?: string | undefined;
209
+ role?: "ADMIN" | "USER" | "HOST" | "MANAGER" | undefined;
210
+ isActive?: boolean | undefined;
211
+ lastLogin?: Date | null | undefined;
212
+ }>, {
213
+ name?: string | undefined;
214
+ email?: string | undefined;
215
+ role?: "ADMIN" | "USER" | "HOST" | "MANAGER" | undefined;
216
+ isActive?: boolean | undefined;
217
+ lastLogin?: Date | null | undefined;
218
+ }, {
219
+ name?: string | undefined;
220
+ email?: string | undefined;
221
+ role?: "ADMIN" | "USER" | "HOST" | "MANAGER" | undefined;
222
+ isActive?: boolean | undefined;
223
+ lastLogin?: Date | null | undefined;
224
+ }>;
225
+ /**
226
+ * Schema for user login credentials.
227
+ * Used for authenticating users in the system.
228
+ *
229
+ * @property {string} email - The user's email address.
230
+ * @property {string} password - The user's password.
231
+ */
232
+ export declare const UserLoginSchema: z.ZodObject<Pick<{
233
+ id: z.ZodNumber;
234
+ name: z.ZodString;
235
+ email: z.ZodString;
236
+ role: z.ZodNativeEnum<{
237
+ readonly ADMIN: "ADMIN";
238
+ readonly USER: "USER";
239
+ readonly HOST: "HOST";
240
+ readonly MANAGER: "MANAGER";
241
+ }>;
242
+ isActive: z.ZodDefault<z.ZodBoolean>;
243
+ password: z.ZodString;
244
+ createdAt: z.ZodDefault<z.ZodDate>;
245
+ updatedAt: z.ZodDefault<z.ZodDate>;
246
+ lastLogin: z.ZodNullable<z.ZodOptional<z.ZodDate>>;
247
+ }, "email" | "password">, "strip", z.ZodTypeAny, {
248
+ email: string;
249
+ password: string;
250
+ }, {
251
+ email: string;
252
+ password: string;
253
+ }>;
254
+ /**
255
+ * User types
256
+ */
257
+ /**
258
+ * Type definition for a complete user object.
259
+ * This type is inferred from the UserSchema, ensuring type safety when working with user data.
260
+ * @typedef {Object} UserDto
261
+ * @property {number} id - The unique identifier for the user
262
+ * @property {string} name - The user's full name
263
+ * @property {string} email - The user's email address
264
+ * @property {Role} role - The user's role in the system
265
+ * @property {boolean} isActive - Whether the user account is active
266
+ * @property {string} password - The user's hashed password
267
+ * @property {Date} createdAt - The timestamp when the user account was created
268
+ * @property {Date} updatedAt - The timestamp when the user account was last updated
269
+ * @property {Date | null} [lastLogin] - The timestamp of the user's last login (optional)
270
+ */
271
+ export type UserDto = z.infer<typeof UserSchema>;
272
+ /**
273
+ * Type definition for the data required to create a new user.
274
+ * This type is inferred from the CreateUserSchema, ensuring type safety when creating users.
275
+ *
276
+ * @property {string} name - The user's name (non-empty string)
277
+ * @property {string} email - The user's email address (valid email format)
278
+ * @property {Role} role - The user's role in the system. Must be one of the following:
279
+ * - ADMIN: Administrator with full system access
280
+ * - USER: Standard user with basic privileges
281
+ * - HOST: User with hosting capabilities
282
+ * - MANAGER: User with management responsibilities
283
+ * @property {string} password - The user's password (will be hashed before storage)
284
+ *
285
+ * @see {@link Role} for the complete list of available roles
286
+ * @see {@link UserSchema} for the full user schema including additional fields
287
+ */
288
+ export type CreateUserDto = z.infer<typeof CreateUserSchema>;
289
+ /**
290
+ * Type definition for an ID parameter.
291
+ * This type is inferred from the IdParamSchema.
292
+ *
293
+ * @property {string} id - The unique identifier (non-empty string)
294
+ */
295
+ export type IdParamDto = z.infer<typeof IdParamSchema>;
296
+ /**
297
+ * Represents the shape of query parameters used for user-related operations.
298
+ * This type is inferred from the UserParamSchema, ensuring type safety and consistency
299
+ * with the defined schema for user query parameters.
300
+ *
301
+ *
302
+ * @property {number} [id] - The user's ID (optional)
303
+ * @property {string} [email] - The user's email address (optional)
304
+ * @property {string} [name] - The user's name (optional, minimum 3 characters)
305
+ * @property {number} [page] - The page number for pagination (optional)
306
+ * @property {number} [pageSize] - The number of items per page (optional)
307
+ * @property {UserSortColumn} [sortBy] - The column to sort by (optional)
308
+ * @property {'asc' | 'desc'} [sortOrder] - The order to sort in (optional)
309
+ * @property {Role} [role] - The user's role (optional)
310
+ * @property {boolean} [isActive] - The user's active status (optional)
311
+ * @property {string} [createdAfter] - The date after which users were created (optional)
312
+ * @property {string} [createdBefore] - The date before which users were created (optional)
313
+ * @see {@link UserSortColumn} for the available sort columns
314
+ * @see {@link Role} for the available user roles
315
+ */
316
+ export type UserSearchCriteria = z.infer<typeof UserParamSchema>;
317
+ /**
318
+ * Type definition for updating user information.
319
+ * This type is inferred from the UpdateUserSchema.
320
+ *
321
+ * @property {string} [name] - The user's new name (optional, minimum 1 character)
322
+ * @property {string} [email] - The user's new email address (optional)
323
+ * @property {Role} [role] - The user's new role (optional)
324
+ * @property {boolean} [isActive] - The user's new active status (optional)
325
+ *
326
+ * @see {@link Role} for the available user roles
327
+ */
328
+ export type UpdateUserDto = z.infer<typeof UpdateUserSchema>;
329
+ /**
330
+ * Type definition for user validation credentials.
331
+ * This type is inferred from the UserLoginSchema and used for authenticating users.
332
+ *
333
+ * @property {string} email - The user's email address
334
+ * @property {string} password - The user's password
335
+ */
336
+ export type UserCredentials = z.infer<typeof UserLoginSchema>;
337
+ /**
338
+ * Type definition for validated user data.
339
+ * This type represents the user data after successful authentication, excluding sensitive information.
340
+ *
341
+ * @property {number} id - The unique identifier for the user
342
+ * @property {string} name - The user's full name
343
+ * @property {string} email - The user's email address
344
+ * @property {Role} role - The user's role in the system
345
+ */
346
+ export type ValidatedUserData = Omit<UserDto, 'password' | 'isActive' | 'createdAt' | 'updatedAt' | 'lastLogin'>;
347
+ /**
348
+ * Type definition for a user list item.
349
+ * This type represents a user in a list view, excluding the password for security reasons.
350
+ *
351
+ * @property {number} id - The unique identifier for the user
352
+ * @property {string} name - The user's full name
353
+ * @property {string} email - The user's email address
354
+ * @property {Role} role - The user's role in the system
355
+ * @property {boolean} isActive - Whether the user account is active
356
+ * @property {Date} createdAt - The timestamp when the user account was created
357
+ * @property {Date} updatedAt - The timestamp when the user account was last updated
358
+ * @property {Date | null} [lastLogin] - The timestamp of the user's last login (optional)
359
+ */
360
+ export type UserListItem = Omit<UserDto, 'password'>;
361
+ /**
362
+ * Represents the result of a user list query.
363
+ * This type encapsulates both the list of users and the total count of users matching the query criteria.
364
+ *
365
+ * @see {@link UserListItem}
366
+ * @property { UserListItem[]} users - An array of user objects, each containing non-sensitive user information.
367
+ * @property {number} totalCount - The total number of users that match the query criteria, regardless of pagination.
368
+ */
369
+ export type UserListResult = {
370
+ users: UserListItem[];
371
+ totalCount: number;
372
+ page: number;
373
+ pageSize: number;
374
+ totalPages: number;
375
+ };
376
+ /**
377
+ * Represents the filters that can be applied when querying users.
378
+ *
379
+ * @interface IUserFilters
380
+ * @property {Role} [role] - Optional. The role to filter users by.
381
+ * @property {boolean} [isActive] - Optional. Whether to filter for active or inactive users.
382
+ * @property {Date} [createdAfter] - Optional. The date after which users were created.
383
+ * @property {Date} [createdBefore] - Optional. The date before which users were created.
384
+ * @see {@link Role} for the available user roles.
385
+ */
386
+ export type IUserFilters = {
387
+ role?: UserRole;
388
+ isActive?: boolean;
389
+ createdAfter?: Date;
390
+ createdBefore?: Date;
391
+ };
392
+ /**
393
+ * Type definition for creating a new user.
394
+ * This type is inferred from the CreateUserSchema and contains all necessary fields for user creation.
395
+ *
396
+ * @property {string} name - The user's full name
397
+ * @property {string} email - The user's email address
398
+ * @property {Role} role - The user's role in the system
399
+ * @property {string} password - The user's password (will be hashed before storage)
400
+ * @see {@link Role} for the available user roles
401
+ */
402
+ export type CreateUser = z.infer<typeof CreateUserSchema>;
403
+ /**
404
+ * Type definition for data returned after creating a new user.
405
+ * This type contains only non-sensitive information about the newly created user.
406
+ *
407
+ * @property {string} name - The user's full name
408
+ * @property {string} email - The user's email address
409
+ */
410
+ export type CreatedUserData = Pick<UserDto, 'name' | 'email'>;
411
+ //# sourceMappingURL=user.dto.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.dto.d.ts","sourceRoot":"","sources":["../../src/dto/user.dto.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC;;GAEG;AAEH,eAAO,MAAM,cAAc;;;;;;;CAOjB,CAAC;AAEX,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAClF;;;GAGG;AAEH;;;;GAIG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUrB,CAAC;AAEH;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;EAK3B,CAAC;AAEH;;;;;GAKG;AACH,eAAO,MAAM,aAAa;;;;;;EAExB,CAAC;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0CjB,CAAC;AAEZ;;;;;;;;GAQG;AACH,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAW1B,CAAC;AAEJ;;;;;;GAMG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;EAG1B,CAAC;AAEH;;GAEG;AAEH;;;;;;;;;;;;;GAaG;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAC;AAEjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,CAAC,KAAK,CAA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M,MAAM,eAAe,GAAG,IAAI,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC"}
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UserLoginSchema = exports.UpdateUserSchema = exports.UserParamSchema = exports.IdParamSchema = exports.CreateUserSchema = exports.UserSchema = exports.UserSortColumn = void 0;
4
+ const zod_1 = require("zod");
5
+ const enums_1 = require("./enums");
6
+ /**
7
+ * User-related constants
8
+ */
9
+ exports.UserSortColumn = {
10
+ ID: 'id',
11
+ NAME: 'name',
12
+ EMAIL: 'email',
13
+ ROLE: 'role',
14
+ CREATED_AT: 'createdAt',
15
+ UPDATED_AT: 'updatedAt',
16
+ };
17
+ /**
18
+ *
19
+ * User schemas
20
+ */
21
+ /**
22
+ * Schema for a complete user object.
23
+ * This schema defines all the fields that a user can have in the system.
24
+ * It uses Zod for runtime type checking and validation.
25
+ */
26
+ exports.UserSchema = zod_1.z.object({
27
+ id: zod_1.z.number().min(1, { message: 'ID must not be empty' }),
28
+ name: zod_1.z.string().min(1, { message: 'Name must not be empty' }),
29
+ email: zod_1.z.string().email({ message: 'Invalid email address' }),
30
+ role: zod_1.z.nativeEnum(enums_1.UserRole, { message: 'Invalid role' }),
31
+ isActive: zod_1.z.boolean().default(true),
32
+ password: zod_1.z.string(),
33
+ createdAt: zod_1.z.date().default(() => new Date()),
34
+ updatedAt: zod_1.z.date().default(() => new Date()),
35
+ lastLogin: zod_1.z.date().optional().nullable(),
36
+ });
37
+ /**
38
+ * Schema for creating a new user.
39
+ * This schema picks specific fields from the UserSchema to ensure only necessary data is provided when creating a user.
40
+ *
41
+ * @remarks
42
+ * The schema includes the following fields:
43
+ * - name: The user's name
44
+ * - email: The user's email address
45
+ * - role: The user's role in the system
46
+ * - password: The user's password
47
+ *
48
+ * @returns A Zod schema object that can be used to validate data for creating a new user
49
+ */
50
+ exports.CreateUserSchema = exports.UserSchema.pick({
51
+ name: true,
52
+ email: true,
53
+ role: true,
54
+ password: true,
55
+ });
56
+ /**
57
+ * Schema for a single ID parameter.
58
+ * Used when an API endpoint requires only an ID as input.
59
+ *
60
+ * @property {string} id - The unique identifier (non-empty string).
61
+ */
62
+ exports.IdParamSchema = zod_1.z.object({
63
+ id: zod_1.z.string().min(1, { message: 'ID must not be empty' }),
64
+ });
65
+ /**
66
+ * Schema for user query parameters.
67
+ * This schema defines and validates the structure of query parameters used for searching, filtering, and sorting users.
68
+ *
69
+ * @param {object} params - The object containing user query parameters
70
+ * @param {string} [params.id] - The user's ID (optional, will be transformed to a number)
71
+ * @param {string} [params.email] - The user's email address (optional, must be a valid email)
72
+ * @param {string} [params.name] - The user's name (optional, minimum 3 characters)
73
+ * @param {string} [params.page] - The page number for pagination (optional, will be transformed to a number)
74
+ * @param {string} [params.pageSize] - The number of items per page (optional, will be transformed to a number)
75
+ * @param {UserSortColumn} [params.sortBy] - The column to sort by (optional, must be a valid UserSortColumn)
76
+ * @param {'asc' | 'desc'} [params.sortOrder] - The order to sort in (optional, 'asc' or 'desc')
77
+ * @param {string} [params.role] - The user's role (optional, will be transformed to uppercase and validated against Role enum)
78
+ * @param {boolean} [params.isActive] - The user's active status (optional)
79
+ * @param {string} [params.createdAfter] - The date after which users were created (optional, must be a valid date string)
80
+ * @param {string} [params.createdBefore] - The date before which users were created (optional, must be a valid date string)
81
+ *
82
+ * @returns {z.ZodObject} A Zod schema object that can be used to validate and transform user query parameters
83
+ */
84
+ exports.UserParamSchema = zod_1.z
85
+ .object({
86
+ id: zod_1.z.coerce.number(),
87
+ email: zod_1.z.string().email().optional(),
88
+ name: zod_1.z.string().min(3).optional(),
89
+ page: zod_1.z
90
+ .string()
91
+ .optional()
92
+ .transform((value) => (value ? parseInt(value) : undefined)),
93
+ pageSize: zod_1.z
94
+ .string()
95
+ .optional()
96
+ .transform((value) => (value ? parseInt(value) : undefined)),
97
+ sortBy: zod_1.z.nativeEnum(exports.UserSortColumn).optional(),
98
+ sortOrder: zod_1.z.enum(['asc', 'desc']).optional(),
99
+ role: zod_1.z
100
+ .string()
101
+ .optional()
102
+ .transform((value) => value === null || value === void 0 ? void 0 : value.toUpperCase())
103
+ .pipe(zod_1.z.nativeEnum(enums_1.UserRole))
104
+ .optional(),
105
+ isActive: zod_1.z
106
+ .enum(['true', 'false'])
107
+ .optional()
108
+ .transform((val) => {
109
+ if (val === 'true')
110
+ return true;
111
+ if (val === 'false')
112
+ return false;
113
+ return undefined;
114
+ }),
115
+ createdAfter: zod_1.z
116
+ .string()
117
+ .optional()
118
+ .refine((value) => !value || !isNaN(Date.parse(value)), {
119
+ message: 'createdAfter must be a valid date string',
120
+ }),
121
+ createdBefore: zod_1.z
122
+ .string()
123
+ .optional()
124
+ .refine((value) => !value || !isNaN(Date.parse(value)), {
125
+ message: 'createdBefore must be a valid date string',
126
+ }),
127
+ })
128
+ .partial();
129
+ /**
130
+ * Schema for updating user information.
131
+ * All fields are optional, but at least one must be provided.
132
+ *
133
+ * @property {string} [name] - The user's new name (optional, minimum 1 character).
134
+ * @property {string} [email] - The user's new email address (optional).
135
+ * @property {Role} [role] - The user's new role (optional).
136
+ * @property {boolean} [isActive] - The user's new active status (optional).
137
+ */
138
+ exports.UpdateUserSchema = exports.UserSchema.pick({
139
+ name: true,
140
+ email: true,
141
+ role: true,
142
+ isActive: true,
143
+ lastLogin: true,
144
+ })
145
+ .partial()
146
+ .refine((data) => Object.values(data).some((value) => value !== undefined), {
147
+ message: 'At least one field must be provided in the body',
148
+ path: ['name', 'email', 'role', 'isActive', 'lastLogin'],
149
+ });
150
+ /**
151
+ * Schema for user login credentials.
152
+ * Used for authenticating users in the system.
153
+ *
154
+ * @property {string} email - The user's email address.
155
+ * @property {string} password - The user's password.
156
+ */
157
+ exports.UserLoginSchema = exports.UserSchema.pick({
158
+ email: true,
159
+ password: true,
160
+ });
161
+ //# sourceMappingURL=user.dto.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user.dto.js","sourceRoot":"","sources":["../../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I,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,EAAE;IAC3E,OAAO,EAAE,iDAAiD;IAC1D,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,WAAW,CAAC;CACxD,CAAC,CAAC;AAEJ;;;;;;GAMG;AACU,QAAA,eAAe,GAAG,kBAAU,CAAC,IAAI,CAAC;IAC9C,KAAK,EAAE,IAAI;IACX,QAAQ,EAAE,IAAI;CACd,CAAC,CAAC"}
@@ -0,0 +1,2 @@
1
+ export * from './dto';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./dto"), exports);
18
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,wCAAsB"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@servemate/dto",
3
+ "version": "1.0.0",
4
+ "description": "DTO package for ServeMate service",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "files": [
8
+ "dist"
9
+ ],
10
+ "scripts": {
11
+ "build": "tsc",
12
+ "clean": "rm -rf dist",
13
+ "prebuild": "npm run clean",
14
+ "prepare": "npm run build",
15
+ "test": "echo \"No tests specified\"",
16
+ "pack": "npm pack --dry-run"
17
+ },
18
+ "dependencies": {
19
+ "zod": "^3.23.8"
20
+ },
21
+ "devDependencies": {
22
+ "typescript": "^5.7.2"
23
+ },
24
+ "peerDependencies": {
25
+ "zod": "^3.0.0"
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "git+https://github.com/inmorpher/ServeMate-DTO.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/inmorpher/ServeMate-DTO/issues"
33
+ },
34
+ "homepage": "https://github.com/inmorpher/ServeMate-DTO#readme",
35
+ "keywords": [
36
+ "dto",
37
+ "servemate",
38
+ "typescript"
39
+ ],
40
+ "author": "",
41
+ "license": "ISC",
42
+ "publishConfig": {
43
+ "access": "public"
44
+ }
45
+ }