1.0.8 • Published 2 months ago
@servemate/dto v1.0.8
@servemate/dto
Data Transfer Objects (DTOs) package for the ServeMate restaurant management service. This package provides strongly typed DTOs using Zod for runtime validation.
This package is part of the ServeMate restaurant management system.
Installation
npm install @servemate/dto
Features
- Type-safe DTOs for all service entities
- Runtime validation using Zod
- Comprehensive enum support
- Full TypeScript support
- Zero external dependencies (except Zod)
- Automatic type inference from schemas
- Built-in search criteria validation
- Pagination support for list operations
Available DTOs
User Management
UserDTO
- Complete user data structureCreateUserDTO
- For user creationUpdateUserDTO
- For partial user updatesUserSearchDTO
- For user search queriesUserCredentials
- For authenticationUserListResult
- For paginated user lists
Order Management
OrderDTO
- Complete order structureOrderCreateDTO
- For creating new ordersOrderUpdateDTO
- For updating ordersOrderSearchDTO
- For order queriesOrderItemDTO
- For individual order itemsOrderFullSingleDTO
- Detailed order informationOrderWithItemsDTO
- Order with associated itemsGuestItemsDTO
- Guest-specific order itemsOrderSearchListResult
- Paginated order search results
Payment Processing
PaymentDTO
- Complete payment dataPaymentSearchDTO
- For payment queriesRefundDTO
- For refund operationsPaymentListDTO
- For paginated payment listsPaymentStatusDTO
- Payment status informationPartialPaymentDTO
- For partial payment updates
Table Management
TablesDTO
- Complete table dataTableCreateDTO
- For creating tablesTableUpdateDTO
- For updating tablesTableSearchDTO
- For table queriesTableAssignmentDTO
- For server assignmentsTableSeatingDTO
- For seating assignmentsTableListItem
- Simplified table informationTablesList
- Paginated table list
Menu Items
FoodItemDTO
- For food itemsDrinkItemDTO
- For drink itemsCreateFoodItemDTO
- For creating food itemsCreateDrinkItemDTO
- For creating drink itemsUpdateFoodItemDTO
- For updating food itemsUpdateDrinkItemDTO
- For updating drink itemsFoodItemsListDTO
- Paginated food items listDrinkItemsListDTO
- Paginated drink items listSearchFoodItemsDTO
- For food item searchesSearchDrinkItemsDTO
- For drink item searches
Enums
User Related
import { UserRole } from '@servemate/dto';
// Available roles
UserRole.ADMIN;
UserRole.USER;
UserRole.HOST;
UserRole.MANAGER;
Order Related
import { OrderState } from '@servemate/dto';
// Order states
OrderState.AWAITING;
OrderState.RECEIVED;
OrderState.SERVED;
OrderState.CANCELED;
OrderState.DISPUTED;
OrderState.READY_TO_PAY;
OrderState.COMPLETED;
Payment Related
import { PaymentMethod, PaymentState } from '@servemate/dto';
// Payment methods
PaymentMethod.CASH;
PaymentMethod.CREDIT_CARD;
PaymentMethod.DEBIT_CARD;
// Payment states
PaymentState.NONE;
PaymentState.PAID;
PaymentState.REFUNDED;
PaymentState.CANCELLED;
PaymentState.PENDING;
Menu Items Related
import {
FoodCategory,
DrinkCategory,
FoodType,
SpiceLevel,
DrinkTemp,
Allergy,
} from '@servemate/dto';
// Available categories and types
FoodCategory.APPETIZER;
DrinkCategory.SOFT_DRINK;
FoodType.MAIN_COURSE;
SpiceLevel.NOT_SPICY;
DrinkTemp.COLD;
Table Related
import { TableCondition, SeatingType } from '@servemate/dto';
// Table conditions
TableCondition.AVAILABLE;
TableCondition.OCCUPIED;
TableCondition.RESERVED;
// Seating types
SeatingType.WALK_IN;
SeatingType.RESERVATION;
Usage Examples
Creating a User
import { CreateUserSchema, UserRole } from '@servemate/dto';
const userData = {
name: 'John Doe',
email: 'john@example.com',
role: UserRole.HOST,
password: 'secure123',
};
// Validates the data and returns typed result
const validUser = CreateUserSchema.parse(userData);
Processing an Order
import { OrderSchema, OrderState } from '@servemate/dto';
const orderData = {
tableNumber: 5,
guestsCount: 4,
items: [
{
foodItemId: 1,
quantity: 2,
price: 15.99,
guestNumber: 1,
},
],
status: OrderState.RECEIVED,
};
// Validates the order data
const validOrder = OrderSchema.parse(orderData);
Handling Payments
import { PaymentSchema, PaymentMethod, PaymentState } from '@servemate/dto';
const paymentData = {
amount: 50.0,
paymentType: PaymentMethod.CREDIT_CARD,
orderId: 123,
status: PaymentState.PAID,
tax: 5.0,
tip: 7.5,
};
// Validates payment data
const validPayment = PaymentSchema.parse(paymentData);
Managing Tables
import { TableCreateSchema, TableCondition } from '@servemate/dto';
const tableData = {
tableNumber: 10,
capacity: 4,
status: TableCondition.AVAILABLE,
};
// Validates table data
const validTable = TableCreateSchema.parse(tableData);
Search Criteria Usage
import { TableSearchCriteriaSchema, TableSortOptionsEnum } from '@servemate/dto';
const searchCriteria = {
minCapacity: 4,
maxCapacity: 8,
isOccupied: false,
page: 1,
pageSize: 10,
sortBy: TableSortOptionsEnum.CAPACITY,
sortOrder: 'asc',
};
// Validates search criteria
const validCriteria = TableSearchCriteriaSchema.parse(searchCriteria);
Contributing
Please read our contributing guide for details on our code of conduct and the process for submitting pull requests.
License
ISC
Support
For support, please raise an issue in our issue tracker.