-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-dashboard.js
More file actions
172 lines (152 loc) · 5.75 KB
/
Copy pathtest-dashboard.js
File metadata and controls
172 lines (152 loc) · 5.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
// Test script to verify role-specific login and dashboard endpoints
const express = require('express');
const app = require('./server');
console.log('✅ Role-specific authentication and dashboard endpoints created successfully!');
console.log('\n📋 Enhanced Authentication Features:');
console.log('- Role-specific login responses with dashboard routing info');
console.log('- JWT tokens include role and verification status');
console.log('- Separate dashboard endpoints for businesses and riders');
console.log('- Role-based access control middleware');
console.log('- Rider availability management');
console.log('\n🔐 Authentication Endpoints:');
console.log('- POST /api/auth/login - Enhanced login with dashboard info');
console.log('- GET /api/auth/dashboard/business - Business dashboard data');
console.log('- GET /api/auth/dashboard/rider - Rider dashboard data');
console.log('- PATCH /api/auth/rider/availability - Update rider availability');
console.log('\n📝 Sample Login Response Structure:');
const sampleLoginResponse = {
token: "jwt_token_here",
user: {
id: "user_id",
name: "John Doe",
email: "john@business.com",
role: "business",
isVerified: false,
businessName: "Quick Delivery Co",
businessAddress: {
street: "123 Main St",
city: "New York",
state: "NY",
zipCode: "10001"
},
businessPhone: "+1-555-0123"
},
dashboard: {
defaultRoute: "/business/dashboard",
availableRoutes: [
"/business/dashboard",
"/business/offers",
"/business/offers/create",
"/business/payments",
"/business/profile"
]
},
message: "Welcome back, John Doe!"
};
console.log(JSON.stringify(sampleLoginResponse, null, 2));
console.log('\n📊 Business Dashboard Data Structure:');
const businessDashboard = {
profile: "user_profile_data",
stats: {
totalOffers: 0,
activeOffers: 0,
completedOffers: 0,
totalSpent: 0
},
recentActivity: [],
quickActions: [
{ label: 'Post New Offer', route: '/business/offers/create' },
{ label: 'View Active Offers', route: '/business/offers' },
{ label: 'Payment History', route: '/business/payments' },
{ label: 'Update Profile', route: '/business/profile' }
]
};
console.log(JSON.stringify(businessDashboard, null, 2));
console.log('\n🚴 Rider Dashboard Data Structure:');
const riderDashboard = {
profile: "user_profile_data",
stats: {
totalEarnings: 0,
completedDeliveries: 0,
currentRating: 5.0,
availableOffers: 0
},
availability: {
isAvailable: false,
currentLocation: null
},
recentActivity: [],
quickActions: [
{ label: 'Find Offers', route: '/rider/offers' },
{ label: 'View Deliveries', route: '/rider/deliveries' },
{ label: 'Check Earnings', route: '/rider/earnings' },
{ label: 'Update Availability', route: '/rider/profile' }
]
};
console.log(JSON.stringify(riderDashboard, null, 2));
console.log('\n📋 Example curl commands to test:');
console.log('\n# 1. Register a business:');
console.log(`curl -X POST http://localhost:5000/api/auth/register/business \\
-H "Content-Type: application/json" \\
-d '{
"name": "John Doe",
"email": "john@business.com",
"password": "password123",
"businessName": "Quick Delivery Co",
"businessAddress": {
"street": "123 Main St",
"city": "New York",
"state": "NY",
"zipCode": "10001"
},
"businessPhone": "+1-555-0123"
}'`);
console.log('\n# 2. Login as business (note the dashboard routing info):');
console.log(`curl -X POST http://localhost:5000/api/auth/login \\
-H "Content-Type: application/json" \\
-d '{"email": "john@business.com", "password": "password123"}'`);
console.log('\n# 3. Get business dashboard data (requires auth token):');
console.log(`curl -X GET http://localhost:5000/api/auth/dashboard/business \\
-H "Authorization: Bearer YOUR_JWT_TOKEN"`);
console.log('\n# 4. Register a rider:');
console.log(`curl -X POST http://localhost:5000/api/auth/register/rider \\
-H "Content-Type: application/json" \\
-d '{
"name": "Mike Wilson",
"email": "mike@rider.com",
"password": "password123",
"phone": "+1-555-1234",
"vehicleType": "bike"
}'`);
console.log('\n# 5. Login as rider (note different dashboard routes):');
console.log(`curl -X POST http://localhost:5000/api/auth/login \\
-H "Content-Type: application/json" \\
-d '{"email": "mike@rider.com", "password": "password123"}'`);
console.log('\n# 6. Get rider dashboard data:');
console.log(`curl -X GET http://localhost:5000/api/auth/dashboard/rider \\
-H "Authorization: Bearer YOUR_JWT_TOKEN"`);
console.log('\n# 7. Update rider availability:');
console.log(`curl -X PATCH http://localhost:5000/api/auth/rider/availability \\
-H "Authorization: Bearer YOUR_JWT_TOKEN" \\
-H "Content-Type: application/json" \\
-d '{
"isAvailable": true,
"currentLocation": {
"type": "Point",
"coordinates": [-74.006, 40.7128]
}
}'`);
console.log('\n🚀 Key Features Implemented:');
console.log('✅ Separate registration flows for businesses and riders');
console.log('✅ Role-specific profile validation');
console.log('✅ Enhanced login with dashboard routing information');
console.log('✅ Role-based access control middleware');
console.log('✅ Business dashboard with offer management focus');
console.log('✅ Rider dashboard with earnings and availability focus');
console.log('✅ Rider availability management endpoint');
console.log('\n🎯 Next Steps:');
console.log('- Start MongoDB and the server to test these endpoints');
console.log('- The login response now includes role-specific dashboard routes');
console.log('- Each role gets tailored dashboard data and quick actions');
console.log('- Ready to implement offer management and location services');
process.exit(0);