-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-api-fields.js
More file actions
107 lines (93 loc) · 3.55 KB
/
test-api-fields.js
File metadata and controls
107 lines (93 loc) · 3.55 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
// Test API response structure to verify field mappings
async function testAPIStructure() {
try {
console.log('🔍 Testing API field structure...\n');
// Login to get admin token
const loginResponse = await fetch('http://localhost:8000/api/admin/auth/admin-login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
phone: '9999999999',
otp: '123456'
})
});
const loginData = await loginResponse.json();
const token = loginData.data.token;
console.log('✅ Login successful');
// Get bookings with admin token
const bookingsResponse = await fetch('http://localhost:8000/api/admin/bookings', {
headers: {
'Authorization': `Bearer ${token}`
}
});
const bookingsData = await bookingsResponse.json();
const bookings = bookingsData.data;
console.log(`📊 Total bookings: ${bookings.length}\n`);
if (bookings.length > 0) {
const booking = bookings[0];
console.log('🏗️ Booking Structure Analysis:');
console.log('================================');
// Check booking fields
console.log('📋 Booking ID:', booking._id);
console.log('📅 Date:', booking.bookingDate);
console.log('🏷️ Status:', booking.status);
console.log('💰 Total:', booking.totalAmount);
// Check user fields
console.log('\n👤 User Structure:');
if (booking.userId) {
console.log('- Field name: userId (✅)');
console.log('- User name:', booking.userId.name);
console.log('- User email:', booking.userId.email);
console.log('- User mobile:', booking.userId.mobileNo);
} else if (booking.user) {
console.log('- Field name: user');
} else {
console.log('- No user data found');
}
// Check vendor fields
console.log('\n🔧 Vendor Structure:');
if (booking.vendorId) {
console.log('- Field name: vendorId (✅)');
if (booking.vendorId) {
console.log('- Vendor name:', booking.vendorId.name);
console.log('- Vendor mobile:', booking.vendorId.mobileNo);
console.log('- Vendor verified:', booking.vendorId.isVerify);
} else {
console.log('- No vendor assigned');
}
} else if (booking.vendor) {
console.log('- Field name: vendor');
} else {
console.log('- No vendor data found');
}
// Check service fields
console.log('\n🛠️ Service Structure:');
if (booking.serviceId) {
console.log('- Field name: serviceId (✅)');
if (booking.serviceId.serviceName) {
console.log('- Service name:', booking.serviceId.serviceName);
console.log('- Service type:', booking.serviceId.serviceType);
console.log('- Service category:', booking.serviceId.category);
} else {
console.log('- Service not populated');
}
} else if (booking.service) {
console.log('- Field name: service');
} else {
console.log('- No service data found');
}
console.log('\n📝 Full booking object keys:', Object.keys(booking));
} else {
console.log('❌ No bookings found');
}
} catch (error) {
console.error('❌ Error:', error.message);
if (error.message.includes('Unexpected token')) {
console.log('\n💡 Tip: Backend might be returning HTML error page instead of JSON');
console.log(' Check if backend is running on port 8000');
}
}
}
testAPIStructure();