-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdebug-admin-data.js
More file actions
94 lines (80 loc) · 3.28 KB
/
debug-admin-data.js
File metadata and controls
94 lines (80 loc) · 3.28 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
// Debug script to test admin data fetching in browser environment
const API_BASE_URL = 'http://localhost:5000';
async function debugAdminData() {
try {
// Get token from localStorage (simulating browser environment)
const accessToken = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjY4NGFmNWUzY2ZjYzcyYzY3YTU5MDFiMCIsInJvbGUiOiJhZG1pbiIsImlhdCI6MTc1MTUyNzQxNSwiZXhwIjoxNzUxNjEzODE1fQ.Lyv5c6MgnBBIKVQmZOh5cYZhVAy6sEA92wCrzbD1mquY';
console.log('=== Testing Admin Data Fetching ===');
console.log('API_BASE_URL:', API_BASE_URL);
console.log('Access Token:', accessToken ? 'Present' : 'Missing');
// Test 1: Get Users
console.log('\n=== Test 1: Get Users ===');
const usersUrl = `${API_BASE_URL}/api/admin/users`;
console.log('Users URL:', usersUrl);
const usersResponse = await fetch(usersUrl, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`,
'Cache-Control': 'no-cache',
},
});
const usersData = await usersResponse.json();
console.log('Users Response Status:', usersResponse.status);
console.log('Users Response:', {
success: usersData.success,
total: usersData.total,
count: usersData.count,
dataLength: usersData.data?.length,
firstUser: usersData.data?.[0]?.firstName + ' ' + usersData.data?.[0]?.lastName
});
// Test 2: Get Employers
console.log('\n=== Test 2: Get Employers ===');
const employersUrl = `${API_BASE_URL}/api/admin/employers`;
console.log('Employers URL:', employersUrl);
const employersResponse = await fetch(employersUrl, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`,
'Cache-Control': 'no-cache',
},
});
const employersData = await employersResponse.json();
console.log('Employers Response Status:', employersResponse.status);
console.log('Employers Response:', {
success: employersData.success,
total: employersData.total,
count: employersData.count,
dataLength: employersData.data?.length,
firstEmployer: employersData.data?.[0]?.companyName
});
// Test 3: Dashboard Stats
console.log('\n=== Test 3: Dashboard Stats ===');
const dashboardUrl = `${API_BASE_URL}/api/admin/dashboard`;
console.log('Dashboard URL:', dashboardUrl);
const dashboardResponse = await fetch(dashboardUrl, {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${accessToken}`,
'Cache-Control': 'no-cache',
},
});
const dashboardData = await dashboardResponse.json();
console.log('Dashboard Response Status:', dashboardResponse.status);
console.log('Dashboard Response:', {
success: dashboardData.success,
totalUsers: dashboardData.data?.overview?.totalUsers,
totalEmployers: dashboardData.data?.overview?.totalEmployers,
activeGigs: dashboardData.data?.overview?.activeGigs
});
console.log('\n=== Debug Complete ===');
} catch (error) {
console.error('Debug Error:', error);
}
}
if (typeof window !== 'undefined') {
// Browser environment
debugAdminData();
} else {
// Node.js environment (Node 18+ has built-in fetch)
debugAdminData();
}