Overview
The SkyTeam ROBLOX miles system rewards passengers for flying with alliance airlines. Passengers earn miles during flights and can spend them on products offered by airlines through the admin panel.Miles Balance
Each user has a miles balance stored in their profile:packages/database/src/schema.ts
Default Balance
New users start with 0 miles. Miles are earned by participating in flights.
Earning Miles
Passengers earn miles by participating in flights. The amount is determined when they join a flight:packages/database/src/schema.ts
Incrementing Miles
The system provides a function to safely increment user miles:packages/database/src/users.ts
Transaction Support
The increment function supports database transactions for atomic operations.
Spending Miles
Users can spend miles on products through the airline’s catalog:packages/database/src/users.ts
Balance Validation
The system checks if users have sufficient miles before allowing purchases
Atomic Operations
Miles deduction and transaction logging happen atomically
Miles Products
Airlines can create products that users can purchase with miles:packages/database/src/schema.ts
Fetching Products
Airlines can retrieve their product catalog:apps/api/src/routes/airline.ts
Purchasing Products
Users can buy products through the API:apps/api/src/routes/users.ts
Transaction History
All miles activity is logged for transparency:packages/database/src/schema.ts
Recording Transactions
packages/database/src/miles.ts
Viewing Transaction History
packages/database/src/miles.ts
Best Practices
Use Transactions
Always use database transactions when modifying miles to ensure data consistency
Log Everything
Record all miles changes in the transaction history for audit trails
Validate Balances
Check user balances before allowing purchases to prevent negative balances
Clear Product Names
Use descriptive product names and descriptions for better user experience
Error Handling
The miles system provides clear error messages:- Insufficient miles: User doesn’t have enough miles for a purchase
- User not found: Invalid user ID provided
- Product not found: Product doesn’t exist or is inactive
- Missing productId: Required parameter not provided
Next Steps
Fetch User Data
Learn how to retrieve user miles and flight history