@servemate/dto 1.0.10 → 1.0.21

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/README.md CHANGED
@@ -1,265 +1,226 @@
1
1
  # @servemate/dto
2
2
 
3
- Data Transfer Objects (DTOs) package for the ServeMate restaurant management service. This package provides strongly typed DTOs using Zod for runtime validation.
3
+ [![NPM Version](https://img.shields.io/npm/v/@servemate/dto.svg)](https://www.npmjs.com/package/@servemate/dto)
4
+ [![License](https://img.shields.io/npm/l/@servemate/dto.svg)](https://github.com/inmorpher/ServeMate-DTO/blob/main/LICENSE)
5
+ [![TypeScript](https://img.shields.io/badge/language-typescript-blue.svg)](https://www.typescriptlang.org/)
6
+ [![Zod](https://img.shields.io/badge/validation-Zod-purple.svg)](https://zod.dev/)
4
7
 
5
- This package is part of the [ServeMate](https://github.com/inmorpher/ServeMate-service) restaurant management system.
8
+ **Data Transfer Objects (DTOs) package for the ServeMate restaurant management service.**
6
9
 
7
- ## Installation
10
+ This package provides a comprehensive set of strongly-typed DTOs with runtime validation powered by Zod. It ensures data integrity and consistency across all microservices within the [ServeMate](https://github.com/inmorpher/ServeMate-service) ecosystem.
8
11
 
9
- ```bash
10
- npm install @servemate/dto
11
- ```
12
+ ## Overview
12
13
 
13
- ## Features
14
-
15
- - Type-safe DTOs for all service entities
16
- - Runtime validation using Zod
17
- - Comprehensive enum support
18
- - Full TypeScript support
19
- - Zero external dependencies (except Zod)
20
- - Automatic type inference from schemas
21
- - Built-in search criteria validation
22
- - Pagination support for list operations
23
-
24
- ## Available DTOs
25
-
26
- ### User Management
27
-
28
- - `UserDTO` - Complete user data structure
29
- - `CreateUserDTO` - For user creation
30
- - `UpdateUserDTO` - For partial user updates
31
- - `UserSearchDTO` - For user search queries
32
- - `UserCredentials` - For authentication
33
- - `UserListResult` - For paginated user lists
34
-
35
- ### Order Management
36
-
37
- - `OrderDTO` - Complete order structure
38
- - `OrderCreateDTO` - For creating new orders
39
- - `OrderUpdateDTO` - For updating orders
40
- - `OrderSearchDTO` - For order queries
41
- - `OrderItemDTO` - For individual order items
42
- - `OrderFullSingleDTO` - Detailed order information
43
- - `OrderWithItemsDTO` - Order with associated items
44
- - `GuestItemsDTO` - Guest-specific order items
45
- - `OrderSearchListResult` - Paginated order search results
46
-
47
- ### Payment Processing
48
-
49
- - `PaymentDTO` - Complete payment data
50
- - `PaymentSearchDTO` - For payment queries
51
- - `RefundDTO` - For refund operations
52
- - `PaymentListDTO` - For paginated payment lists
53
- - `PaymentStatusDTO` - Payment status information
54
- - `PartialPaymentDTO` - For partial payment updates
55
-
56
- ### Table Management
57
-
58
- - `TablesDTO` - Complete table data
59
- - `TableCreateDTO` - For creating tables
60
- - `TableUpdateDTO` - For updating tables
61
- - `TableSearchDTO` - For table queries
62
- - `TableAssignmentDTO` - For server assignments
63
- - `TableSeatingDTO` - For seating assignments
64
- - `TableListItem` - Simplified table information
65
- - `TablesList` - Paginated table list
66
-
67
- ### Menu Items
68
-
69
- - `FoodItemDTO` - For food items
70
- - `DrinkItemDTO` - For drink items
71
- - `CreateFoodItemDTO` - For creating food items
72
- - `CreateDrinkItemDTO` - For creating drink items
73
- - `UpdateFoodItemDTO` - For updating food items
74
- - `UpdateDrinkItemDTO` - For updating drink items
75
- - `FoodItemsListDTO` - Paginated food items list
76
- - `DrinkItemsListDTO` - Paginated drink items list
77
- - `SearchFoodItemsDTO` - For food item searches
78
- - `SearchDrinkItemsDTO` - For drink item searches
14
+ `@servemate/dto` is a centralized repository for all data contracts used in the ServeMate platform. By defining clear and strict schemas, it helps prevent common data-related errors, simplifies API development, and enables seamless communication between different parts of the system.
79
15
 
80
- ## Enums
16
+ ## Key Features
81
17
 
82
- ### User Related
18
+ - **Type-Safe by Default**: Leverages TypeScript and Zod to provide compile-time and runtime type safety.
19
+ - **Runtime Validation**: Ensures that all incoming and outgoing data conforms to the expected structure.
20
+ - **Automatic Type Inference**: Automatically generate TypeScript types from Zod schemas, reducing code duplication.
21
+ - **Comprehensive DTOs**: Covers all domains of the restaurant management system, including users, orders, payments, tables, and menu items.
22
+ - **Search & Pagination**: Built-in support for complex search criteria and paginated responses.
23
+ - **Zero Dependencies**: Other than `zod` as a peer dependency, this package is completely self-contained.
83
24
 
84
- ```typescript
85
- import { UserRole } from '@servemate/dto';
25
+ ## Installation
86
26
 
87
- // Available roles
88
- UserRole.ADMIN;
89
- UserRole.USER;
90
- UserRole.HOST;
91
- UserRole.MANAGER;
27
+ ```bash
28
+ npm install @servemate/dto
92
29
  ```
93
30
 
94
- ### Order Related
31
+ or with Yarn:
95
32
 
96
- ```typescript
97
- import { OrderState } from '@servemate/dto';
98
-
99
- // Order states
100
- OrderState.AWAITING;
101
- OrderState.RECEIVED;
102
- OrderState.SERVED;
103
- OrderState.CANCELED;
104
- OrderState.DISPUTED;
105
- OrderState.READY_TO_PAY;
106
- OrderState.COMPLETED;
33
+ ```bash
34
+ yarn add @servemate/dto
107
35
  ```
108
36
 
109
- ### Payment Related
37
+ > **Note**: This package requires `zod` as a peer dependency. Please ensure it is installed in your project.
38
+ >
39
+ > ```bash
40
+ > npm install zod
41
+ > ```
42
+
43
+ ## Available DTOs and Schemas
44
+
45
+ This package is organized into several domains, each with its own set of DTOs and validation schemas.
46
+
47
+ <details>
48
+ <summary><strong>User Management</strong></summary>
49
+
50
+ | Schema | Description |
51
+ | ------------------- | ----------------------------------------- |
52
+ | `UserSchema` | Complete user data structure. |
53
+ | `CreateUserSchema` | For creating a new user. |
54
+ | `UpdateUserSchema` | For partial user updates. |
55
+ | `UserSearchSchema` | For user search queries. |
56
+ | `UserCredentials` | For authentication purposes. |
57
+ | `UserListResult` | For paginated lists of users. |
58
+
59
+ </details>
60
+
61
+ <details>
62
+ <summary><strong>Order Management</strong></summary>
63
+
64
+ | Schema | Description |
65
+ | --------------------- | ----------------------------------------- |
66
+ | `OrderSchema` | Complete order structure. |
67
+ | `OrderCreateSchema` | For creating a new order. |
68
+ | `OrderUpdateSchema` | For updating an existing order. |
69
+ | `OrderSearchSchema` | For order search queries. |
70
+ | `OrderItemSchema` | For individual items within an order. |
71
+ | `OrderFullSingleDTO` | Detailed information for a single order. |
72
+ | `OrderWithItemsDTO` | An order with its associated items. |
73
+ | `GuestItemsDTO` | Guest-specific order items. |
74
+ | `OrderSearchListResult`| For paginated lists of orders. |
75
+
76
+ </details>
77
+
78
+ <details>
79
+ <summary><strong>Payment Processing</strong></summary>
80
+
81
+ | Schema | Description |
82
+ | ------------------- | ----------------------------------------- |
83
+ | `PaymentSchema` | Complete payment data structure. |
84
+ | `PaymentSearchSchema`| For payment search queries. |
85
+ | `RefundSchema` | For refund operations. |
86
+ | `PaymentListDTO` | For paginated lists of payments. |
87
+ | `PaymentStatusDTO` | Represents the status of a payment. |
88
+ | `PartialPaymentDTO` | For partial payment updates. |
89
+
90
+ </details>
91
+
92
+ <details>
93
+ <summary><strong>Table Management</strong></summary>
94
+
95
+ | Schema | Description |
96
+ | --------------------- | ----------------------------------------- |
97
+ | `TablesSchema` | Complete table data structure. |
98
+ | `TableCreateSchema` | For creating a new table. |
99
+ | `TableUpdateSchema` | For updating an existing table. |
100
+ | `TableSearchSchema` | For table search queries. |
101
+ | `TableAssignmentSchema`| For assigning servers to tables. |
102
+ | `TableSeatingSchema` | For seating assignments. |
103
+ | `TableListItem` | Simplified table information for lists. |
104
+ | `TablesList` | For paginated lists of tables. |
105
+
106
+ </details>
107
+
108
+ <details>
109
+ <summary><strong>Menu Items</strong></summary>
110
+
111
+ | Schema | Description |
112
+ | ---------------------- | ----------------------------------------- |
113
+ | `FoodItemSchema` | For food items. |
114
+ | `DrinkItemSchema` | For drink items. |
115
+ | `CreateFoodItemSchema` | For creating a new food item. |
116
+ | `CreateDrinkItemSchema`| For creating a new drink item. |
117
+ | `UpdateFoodItemSchema` | For updating an existing food item. |
118
+ | `UpdateDrinkItemSchema`| For updating an existing drink item. |
119
+ | `FoodItemsListDTO` | For paginated lists of food items. |
120
+ | `DrinkItemsListDTO` | For paginated lists of drink items. |
121
+ | `SearchFoodItemsSchema`| For food item search queries. |
122
+ | `SearchDrinkItemsSchema`| For drink item search queries. |
123
+
124
+ </details>
110
125
 
111
- ```typescript
112
- import { PaymentMethod, PaymentState } from '@servemate/dto';
113
-
114
- // Payment methods
115
- PaymentMethod.CASH;
116
- PaymentMethod.CREDIT_CARD;
117
- PaymentMethod.DEBIT_CARD;
118
-
119
- // Payment states
120
- PaymentState.NONE;
121
- PaymentState.PAID;
122
- PaymentState.REFUNDED;
123
- PaymentState.CANCELLED;
124
- PaymentState.PENDING;
125
- ```
126
+ ## Enums
126
127
 
127
- ### Menu Items Related
128
+ The package includes a rich set of enums to ensure consistency for categorical data.
128
129
 
129
130
  ```typescript
130
131
  import {
131
- FoodCategory,
132
- DrinkCategory,
133
- FoodType,
134
- SpiceLevel,
135
- DrinkTemp,
136
- Allergy,
132
+ UserRole,
133
+ OrderState,
134
+ PaymentMethod,
135
+ PaymentState,
136
+ FoodCategory,
137
+ DrinkCategory,
138
+ TableCondition,
139
+ SeatingType
137
140
  } from '@servemate/dto';
138
141
 
139
- // Available categories and types
140
- FoodCategory.APPETIZER;
141
- DrinkCategory.SOFT_DRINK;
142
- FoodType.MAIN_COURSE;
143
- SpiceLevel.NOT_SPICY;
144
- DrinkTemp.COLD;
145
- ```
146
-
147
- ### Table Related
148
-
149
- ```typescript
150
- import { TableCondition, SeatingType } from '@servemate/dto';
151
-
152
- // Table conditions
153
- TableCondition.AVAILABLE;
154
- TableCondition.OCCUPIED;
155
- TableCondition.RESERVED;
156
-
157
- // Seating types
158
- SeatingType.WALK_IN;
159
- SeatingType.RESERVATION;
142
+ // Example usage:
143
+ const role = UserRole.MANAGER;
144
+ const orderState = OrderState.COMPLETED;
145
+ const paymentMethod = PaymentMethod.CREDIT_CARD;
160
146
  ```
161
147
 
162
148
  ## Usage Examples
163
149
 
164
- ### Creating a User
150
+ ### 1. Data Validation
151
+
152
+ Use the Zod schemas to validate data at runtime. This is especially useful for validating incoming API requests.
165
153
 
166
154
  ```typescript
167
- import { CreateUserSchema, UserRole } from '@servemate/dto';
155
+ import { CreateUserSchema } from '@servemate/dto';
168
156
 
169
- const userData = {
170
- name: 'John Doe',
171
- email: 'john@example.com',
172
- role: UserRole.HOST,
173
- password: 'secure123',
157
+ const newUserData = {
158
+ name: 'Jane Doe',
159
+ email: 'jane.doe@example.com',
160
+ role: 'USER',
161
+ password: 'password123'
174
162
  };
175
163
 
176
- // Validates the data and returns typed result
177
- const validUser = CreateUserSchema.parse(userData);
164
+ try {
165
+ const validatedUser = CreateUserSchema.parse(newUserData);
166
+ console.log('User data is valid:', validatedUser);
167
+ // Proceed with user creation...
168
+ } catch (error) {
169
+ console.error('Validation failed:', error);
170
+ }
178
171
  ```
179
172
 
180
- ### Processing an Order
173
+ ### 2. Type Inference
181
174
 
182
- ```typescript
183
- import { OrderSchema, OrderState } from '@servemate/dto';
184
-
185
- const orderData = {
186
- tableNumber: 5,
187
- guestsCount: 4,
188
- items: [
189
- {
190
- foodItemId: 1,
191
- quantity: 2,
192
- price: 15.99,
193
- guestNumber: 1,
194
- },
195
- ],
196
- status: OrderState.RECEIVED,
197
- };
198
-
199
- // Validates the order data
200
- const validOrder = OrderSchema.parse(orderData);
201
- ```
202
-
203
- ### Handling Payments
175
+ Automatically infer TypeScript types from the Zod schemas to keep your code DRY and consistent.
204
176
 
205
177
  ```typescript
206
- import { PaymentSchema, PaymentMethod, PaymentState } from '@servemate/dto';
207
-
208
- const paymentData = {
209
- amount: 50.0,
210
- paymentType: PaymentMethod.CREDIT_CARD,
211
- orderId: 123,
212
- status: PaymentState.PAID,
213
- tax: 5.0,
214
- tip: 7.5,
215
- };
216
-
217
- // Validates payment data
218
- const validPayment = PaymentSchema.parse(paymentData);
178
+ import { z } from 'zod';
179
+ import { OrderSchema, OrderItemSchema } from '@servemate/dto';
180
+
181
+ // Infer the TypeScript type from the schema
182
+ type Order = z.infer<typeof OrderSchema>;
183
+ type OrderItem = z.infer<typeof OrderItemSchema>;
184
+
185
+ function processOrder(order: Order) {
186
+ console.log(`Processing order for table ${order.tableNumber}`);
187
+ order.items.forEach((item: OrderItem) => {
188
+ console.log(`- ${item.quantity}x Item ID: ${item.foodItemId || item.drinkItemId}`);
189
+ });
190
+ }
219
191
  ```
220
192
 
221
- ### Managing Tables
222
-
223
- ```typescript
224
- import { TableCreateSchema, TableCondition } from '@servemate/dto';
225
-
226
- const tableData = {
227
- tableNumber: 10,
228
- capacity: 4,
229
- status: TableCondition.AVAILABLE,
230
- };
231
-
232
- // Validates table data
233
- const validTable = TableCreateSchema.parse(tableData);
234
- ```
193
+ ### 3. Search and Pagination
235
194
 
236
- ### Search Criteria Usage
195
+ The search schemas provide a standardized way to handle complex queries with pagination.
237
196
 
238
197
  ```typescript
239
198
  import { TableSearchCriteriaSchema, TableSortOptionsEnum } from '@servemate/dto';
240
199
 
241
200
  const searchCriteria = {
242
- minCapacity: 4,
243
- maxCapacity: 8,
244
- isOccupied: false,
245
- page: 1,
246
- pageSize: 10,
247
- sortBy: TableSortOptionsEnum.CAPACITY,
248
- sortOrder: 'asc',
201
+ minCapacity: 2,
202
+ maxCapacity: 6,
203
+ status: 'AVAILABLE',
204
+ page: 1,
205
+ pageSize: 20,
206
+ sortBy: TableSortOptionsEnum.CAPACITY,
207
+ sortOrder: 'desc',
249
208
  };
250
209
 
251
- // Validates search criteria
252
- const validCriteria = TableSearchCriteriaSchema.parse(searchCriteria);
210
+ const validatedCriteria = TableSearchCriteriaSchema.parse(searchCriteria);
211
+
212
+ // Use validatedCriteria to fetch data from your service
213
+ // e.g., fetch('/api/tables', { body: JSON.stringify(validatedCriteria) });
253
214
  ```
254
215
 
255
216
  ## Contributing
256
217
 
257
- Please read our [contributing guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
218
+ Contributions are welcome! Please read our [contributing guide](CONTRIBUTING.md) for details on our code of conduct and the process for submitting pull requests.
258
219
 
259
220
  ## License
260
221
 
261
- ISC
222
+ This project is licensed under the ISC License - see the [LICENSE](LICENSE) file for details.
262
223
 
263
224
  ## Support
264
225
 
265
- For support, please raise an issue in our [issue tracker](https://github.com/inmorpher/ServeMate-DTO/issues).
226
+ For support, please open an issue in our [issue tracker](https://github.com/inmorpher/ServeMate-DTO/issues).
@@ -52,17 +52,17 @@ export type ListReturnType<T> = {
52
52
  * @constant
53
53
  * @type {ZodSchema}
54
54
  */
55
- export declare const searchCriteriaSchema: z.ZodObject<z.objectUtil.extendShape<Pick<{
55
+ export declare const searchCriteriaSchema: z.ZodObject<Pick<{
56
56
  page: z.ZodDefault<z.ZodNumber>;
57
57
  pageSize: z.ZodDefault<z.ZodNumber>;
58
58
  totalPages: z.ZodNumber;
59
59
  totalCount: z.ZodNumber;
60
- }, "page" | "pageSize">, {
60
+ }, "page" | "pageSize"> & {
61
61
  sortOrder: z.ZodDefault<z.ZodOptional<z.ZodNativeEnum<{
62
62
  readonly ASC: "asc";
63
63
  readonly DESC: "desc";
64
64
  }>>>;
65
- }>, "strip", z.ZodTypeAny, {
65
+ }, "strip", z.ZodTypeAny, {
66
66
  page: number;
67
67
  pageSize: number;
68
68
  sortOrder: "asc" | "desc";
@@ -1 +1 @@
1
- {"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../src/dto/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,QAAA,MAAM,UAAU;;;CAGN,CAAC;AAEX,eAAO,MAAM,eAAe,UAAW,MAAM,GAAG,MAAM,EAAE,GAAG,SAAS,aAGnE,CAAC;AAEF,eAAO,MAAM,qBAAqB,4FAAgE,CAAC;AAEnG;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;EAK1B,CAAC;AAEH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AAE9D,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI;IAC/B,IAAI,EAAE,CAAC,EAAE,CAA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