194 lines
5.0 KiB
Markdown
194 lines
5.0 KiB
Markdown
# FitAI Report Generation System - Quick Reference
|
|
|
|
## 🚀 Quick Start
|
|
|
|
### 1. Run Admin App
|
|
|
|
```bash
|
|
cd apps/admin
|
|
npm run dev
|
|
# Visit http://localhost:3000
|
|
```
|
|
|
|
### 2. Navigate to Reports
|
|
|
|
- **URL**: `/reports`
|
|
- **Features**: User selection, date range picker, PDF export
|
|
|
|
### 3. Manage Trainer Assignments
|
|
|
|
- **URL**: `/trainer-clients`
|
|
- **Features**: Assign trainers to clients, view active/inactive assignments
|
|
|
|
## 📊 Key Features
|
|
|
|
| Feature | Status | Location |
|
|
| ------------------- | ----------- | -------------------- |
|
|
| Weekly Check-ins | ✅ Complete | Reports page |
|
|
| Nutrition Tracking | ✅ Complete | Reports page |
|
|
| Hydration Tracking | ✅ Complete | Reports page |
|
|
| Fitness Goals | ✅ Complete | Reports page |
|
|
| AI Recommendations | ✅ Complete | Reports page |
|
|
| PDF Export | ✅ Complete | Reports page |
|
|
| Trainer Assignments | ✅ Complete | Trainer-clients page |
|
|
| Role-based Access | ✅ Complete | All pages |
|
|
|
|
## 🔑 Access Control
|
|
|
|
```
|
|
Client ──────────► Own report only
|
|
Trainer ─────────► Assigned clients
|
|
Admin ───────────► Gym users
|
|
SuperAdmin ───────► All users
|
|
```
|
|
|
|
## 📡 API Endpoints
|
|
|
|
### Reports
|
|
|
|
```
|
|
GET /api/reports/user/[userId]?startDate=X&endDate=Y&format=json|pdf
|
|
```
|
|
|
|
### Trainer-Client
|
|
|
|
```
|
|
GET /api/trainer-client # List assignments
|
|
POST /api/trainer-client # Create assignment
|
|
DELETE /api/trainer-client/[id] # Deactivate assignment
|
|
```
|
|
|
|
### Nutrition
|
|
|
|
```
|
|
GET /api/nutrition?date=X|startDate=X&endDate=Y # Get nutrition
|
|
POST /api/nutrition # Save nutrition
|
|
DELETE /api/nutrition?id=X # Delete nutrition
|
|
```
|
|
|
|
### Hydration
|
|
|
|
```
|
|
GET /api/hydration?date=X|startDate=X&endDate=Y # Get hydration
|
|
POST /api/hydration # Save hydration
|
|
DELETE /api/hydration?id=X # Delete hydration
|
|
```
|
|
|
|
## 🗄️ Database Tables
|
|
|
|
| Table | Purpose |
|
|
| ---------------------------- | ---------------------------- |
|
|
| `daily_nutrition` | Daily calorie tracking |
|
|
| `meal_entries` | Individual meal details |
|
|
| `daily_hydration` | Daily water intake |
|
|
| `fitness_profile_history` | Weight/height changes |
|
|
| `trainer_client_assignments` | Trainer-client relationships |
|
|
|
|
## 🎨 UI Pages
|
|
|
|
| Page | URL | Purpose |
|
|
| --------------- | ------------------ | --------------------- |
|
|
| Reports | `/reports` | Generate user reports |
|
|
| Trainer-Clients | `/trainer-clients` | Manage assignments |
|
|
|
|
## 📦 Mobile Integration
|
|
|
|
### Hydration
|
|
|
|
```typescript
|
|
import { useHydration } from "../contexts/HydrationContext";
|
|
|
|
const { todayTotal, addWater } = useHydration();
|
|
await addWater(250); // Adds 250ml
|
|
```
|
|
|
|
### Nutrition
|
|
|
|
```typescript
|
|
import { useNutrition } from "../contexts/NutritionContext";
|
|
|
|
const { todayCalories, addMeal } = useNutrition();
|
|
await addMeal({
|
|
mealType: "breakfast",
|
|
foodName: "Oatmeal",
|
|
calories: 300,
|
|
});
|
|
```
|
|
|
|
## 🧪 Testing
|
|
|
|
```bash
|
|
# Run tests
|
|
cd apps/admin
|
|
npm test
|
|
|
|
# View testing guide
|
|
open docs/TESTING_GUIDE.md
|
|
```
|
|
|
|
## 📝 Example Usage
|
|
|
|
### 1. Create Trainer-Client Assignment
|
|
|
|
```bash
|
|
curl -X POST http://localhost:3000/api/trainer-client \
|
|
-H "Content-Type: application/json" \
|
|
-H "Authorization: Bearer <ADMIN_TOKEN>" \
|
|
-d '{"trainerId": "...", "clientId": "..."}'
|
|
```
|
|
|
|
### 2. Generate Report
|
|
|
|
```bash
|
|
curl "http://localhost:3000/api/reports/user/<USER_ID>?startDate=2024-01-01&endDate=2024-01-31" \
|
|
-H "Authorization: Bearer <TOKEN>"
|
|
```
|
|
|
|
### 3. Download PDF
|
|
|
|
```bash
|
|
curl "http://localhost:3000/api/reports/user/<USER_ID>?format=pdf" \
|
|
-H "Authorization: Bearer <TOKEN>" \
|
|
--output report.pdf
|
|
```
|
|
|
|
## 🔍 Validation Rules
|
|
|
|
| Validation | Rule |
|
|
| ---------------- | ----------------- |
|
|
| Date Format | YYYY-MM-DD only |
|
|
| Future Dates | Allowed |
|
|
| Max Date Range | No limit |
|
|
| Delete Ownership | Must own resource |
|
|
|
|
## 📊 Report Sections
|
|
|
|
1. **User Information** - Name, email, membership
|
|
2. **Report Period** - Start/end dates
|
|
3. **Weekly Check-ins** - ISO weeks (Mon-Sun)
|
|
4. **Nutrition Summary** - Calories, goal achievement
|
|
5. **Hydration Summary** - Water intake, goal %
|
|
6. **Fitness Goals** - Active/completed with progress
|
|
7. **Profile Changes** - Historical data
|
|
8. **Recommendations** - Accepted/rejected/pending
|
|
|
|
## 🎯 Success Criteria
|
|
|
|
- ✅ All 9 phases completed
|
|
- ✅ TypeScript 100% type-safe
|
|
- ✅ Role-based access enforced
|
|
- ✅ PDF export working
|
|
- ✅ Mobile sync functional
|
|
- ✅ Tests passing
|
|
|
|
## 📞 Support
|
|
|
|
- **Docs**: `docs/TESTING_GUIDE.md`
|
|
- **Summary**: `docs/IMPLEMENTATION_SUMMARY.md`
|
|
- **Tests**: `apps/admin/src/app/api/reports/__tests__/`
|
|
|
|
---
|
|
|
|
**Status**: ✅ Production Ready
|
|
**Last Updated**: March 2024
|