-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug-database-state.js
More file actions
136 lines (106 loc) Β· 4.45 KB
/
debug-database-state.js
File metadata and controls
136 lines (106 loc) Β· 4.45 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
#!/usr/bin/env node
/**
* Debug script to check the actual database state
*/
const BASE_URL = 'http://localhost:3000';
async function makeRequest(endpoint, options = {}) {
try {
const response = await fetch(`${BASE_URL}${endpoint}`, {
headers: {
'Content-Type': 'application/json',
...options.headers,
},
...options,
});
const data = await response.json();
return { success: response.ok, data, status: response.status };
} catch (error) {
return { success: false, error: error.message };
}
}
async function checkRealUsers() {
console.log('π Checking Real Users in Database...');
console.log('=' .repeat(50));
const result = await makeRequest('/api/debug/check-real-users');
if (!result.success) {
console.log('β Failed to check real users:', result.error);
return;
}
const { summary, users, usersWithSkills, topSkills, sampleUserSkills } = result.data;
console.log('π Database Summary:');
console.log(` β’ Total Users: ${summary.totalUsers}`);
console.log(` β’ Users with Skills: ${summary.usersWithSkills}`);
console.log(` β’ Total User Skills: ${summary.totalUserSkills}`);
console.log(` β’ Unique Skills: ${summary.uniqueSkills}`);
console.log('\\nπ₯ All Users:');
users.forEach((user, index) => {
console.log(` ${index + 1}. ${user.name} (${user.email}) - ID: ${user.id}`);
});
console.log('\\nπ― Users with Skills:');
usersWithSkills.forEach((user, index) => {
console.log(` ${index + 1}. ${user.name} (${user.email})`);
console.log(` Skills: ${user.skills.map(s => `${s.name} (${s.proficiencyScore}%)`).join(', ')}`);
});
console.log('\\nπ Sample User-Skill Records:');
sampleUserSkills.forEach((record, index) => {
console.log(` ${index + 1}. User: ${record.userName} | Skill: ${record.skillName} | Proficiency: ${record.proficiencyScore}%`);
});
}
async function checkJobs() {
console.log('\\nπ Checking Jobs in Database...');
console.log('=' .repeat(50));
const result = await makeRequest('/api/debug/jobs');
if (!result.success) {
console.log('β Failed to check jobs:', result.error);
return;
}
const { summary, jobs } = result.data;
console.log('π Jobs Summary:');
console.log(` β’ Total Jobs: ${summary.totalJobs}`);
console.log(` β’ Active Jobs: ${summary.activeJobs}`);
console.log('\\nπ All Jobs:');
jobs.forEach((job, index) => {
console.log(` ${index + 1}. ${job.title} (${job.status}) - ID: ${job.id}`);
console.log(` Recruiter: ${job.recruiterId}`);
console.log(` Required Skills: ${job.requiredSkills?.length || 0}`);
console.log(` Preferred Skills: ${job.preferredSkills?.length || 0}`);
});
}
async function testCandidateMatching() {
console.log('\\nπ― Testing Candidate Matching...');
console.log('=' .repeat(50));
// Get first job
const jobsResult = await makeRequest('/api/debug/jobs');
if (!jobsResult.success || !jobsResult.data.jobs.length) {
console.log('β οΈ No jobs found for testing');
return;
}
const firstJob = jobsResult.data.jobs[0];
console.log(`Testing with job: \"${firstJob.title}\" (ID: ${firstJob.id})`);
const result = await makeRequest(`/api/debug/candidate-matching?jobId=${firstJob.id}&limit=10`);
if (!result.success) {
console.log('β Candidate matching failed:', result.data?.error || result.error);
return;
}
const { job, candidates, summary } = result.data.data;
console.log('π Matching Results:');
console.log(` β’ Total Candidates: ${summary.totalCandidates}`);
console.log(` β’ Matched Candidates: ${summary.matchedCandidates}`);
console.log(` β’ Average Match Score: ${summary.averageMatchScore}%`);
console.log('\\nπ Candidates Found:');
candidates.forEach((candidate, index) => {
console.log(` ${index + 1}. ${candidate.candidate.name} (${candidate.match.score}% match)`);
console.log(` Email: ${candidate.candidate.email}`);
console.log(` Skills: ${candidate.candidate.skills.map(s => s.name).join(', ')}`);
console.log(` Matching Skills: ${candidate.match.matchingSkills.map(s => s.name).join(', ')}`);
});
}
async function runDebug() {
console.log('π Database State Debug');
console.log('=' .repeat(60));
await checkRealUsers();
await checkJobs();
await testCandidateMatching();
console.log('\\nβ
Debug complete!');
}
runDebug().catch(console.error);