Codex Assistant
1 天以前 58d9f460b2f8c34430285115e2557d18333c5cab
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
const axios = require('axios');
 
// 配置
const BASE_URL = 'http://localhost:8080/api';
 
// 获取有效token的函数
async function getValidToken() {
    console.log('请提供一个新的微信登录code来获取token...');
    console.log('你可以从微信开发者工具的网络面板中获取最新的code');
    
    // 这里需要用户提供新的code
    const code = 'YOUR_WECHAT_CODE_HERE'; // 用户需要替换这个值
    
    if (code === 'YOUR_WECHAT_CODE_HERE') {
        throw new Error('请先替换脚本中的微信code');
    }
    
    try {
        const response = await axios.post(`${BASE_URL}/auth/wechat-login`, {
            code: code
        });
        
        if (response.data && response.data.token) {
            console.log('✅ 微信登录成功');
            console.log('Token:', response.data.token);
            return response.data.token;
        } else {
            throw new Error('登录响应中没有token');
        }
    } catch (error) {
        console.error('❌ 微信登录失败:', error.response?.data || error.message);
        throw error;
    }
}
 
// 调试用户信息的GraphQL查询
const DEBUG_USER_INFO_QUERY = `
    query DebugUserInfo {
        # 获取当前用户基本信息
        currentUser {
            id
            name
            phone
        }
        
        # 获取当前评委信息
        currentJudgeInfo {
            judgeId
            judgeName
            title
            company
        }
        
        # 获取评审统计(这个查询会检查用户是否是评委)
        reviewStatistics {
            unReviewedCount
            reviewedCount
            studentUnReviewedCount
        }
    }
`;
 
// 测试用户权限的函数
async function testUserPermissions(token) {
    console.log('\n=== 测试用户权限和评委身份 ===');
    
    try {
        const response = await axios.post(`${BASE_URL}/graphql`, {
            query: DEBUG_USER_INFO_QUERY
        }, {
            headers: {
                'Authorization': `Bearer ${token}`,
                'Content-Type': 'application/json'
            }
        });
        
        console.log('HTTP状态码:', response.status);
        
        if (response.data.errors) {
            console.log('❌ GraphQL错误:');
            response.data.errors.forEach((error, index) => {
                console.log(`  ${index + 1}. ${error.message}`);
                if (error.path) {
                    console.log(`     路径: ${error.path.join(' -> ')}`);
                }
            });
        }
        
        if (response.data.data) {
            console.log('✅ 成功获取数据:');
            
            // 检查当前用户信息
            if (response.data.data.currentUser) {
                console.log('📋 当前用户信息:');
                console.log('  用户ID:', response.data.data.currentUser.id);
                console.log('  用户名:', response.data.data.currentUser.name);
                console.log('  手机号:', response.data.data.currentUser.phone);
            } else {
                console.log('⚠️  无法获取当前用户信息');
            }
            
            // 检查评委信息
            if (response.data.data.currentJudgeInfo) {
                console.log('👨‍⚖️ 当前评委信息:');
                console.log('  评委ID:', response.data.data.currentJudgeInfo.judgeId);
                console.log('  评委名:', response.data.data.currentJudgeInfo.judgeName);
                console.log('  职位:', response.data.data.currentJudgeInfo.title);
                console.log('  公司:', response.data.data.currentJudgeInfo.company);
            } else {
                console.log('❌ 当前用户不是评委或无法获取评委信息');
            }
            
            // 检查评审统计
            if (response.data.data.reviewStatistics) {
                console.log('📊 评审统计:');
                console.log('  未评审数量:', response.data.data.reviewStatistics.unReviewedCount);
                console.log('  已评审数量:', response.data.data.reviewStatistics.reviewedCount);
                console.log('  学员未评审数量:', response.data.data.reviewStatistics.studentUnReviewedCount);
            } else {
                console.log('❌ 无法获取评审统计(可能不是评委)');
            }
        }
        
    } catch (error) {
        console.error('❌ 请求失败:', error.response?.data || error.message);
        if (error.response?.status) {
            console.error('HTTP状态码:', error.response.status);
        }
    }
}
 
// 测试简单的评审项目查询
async function testSimpleReviewQuery(token) {
    console.log('\n=== 测试简单的评审项目查询 ===');
    
    const SIMPLE_REVIEW_QUERY = `
        query TestReviewQuery {
            unReviewedProjects(searchKeyword: "", page: 1, pageSize: 5) {
                totalCount
                totalPages
                currentPage
                items {
                    id
                    title
                }
            }
        }
    `;
    
    try {
        const response = await axios.post(`${BASE_URL}/graphql`, {
            query: SIMPLE_REVIEW_QUERY
        }, {
            headers: {
                'Authorization': `Bearer ${token}`,
                'Content-Type': 'application/json'
            }
        });
        
        console.log('HTTP状态码:', response.status);
        
        if (response.data.errors) {
            console.log('❌ GraphQL错误:');
            response.data.errors.forEach((error, index) => {
                console.log(`  ${index + 1}. ${error.message}`);
            });
        }
        
        if (response.data.data) {
            console.log('✅ 查询成功:');
            console.log('未评审项目数量:', response.data.data.unReviewedProjects?.totalCount || 0);
        }
        
    } catch (error) {
        console.error('❌ 查询失败:', error.response?.data || error.message);
    }
}
 
// 主函数
async function main() {
    console.log('🔍 开始调试用户权限和评委身份问题...\n');
    
    try {
        // 获取token
        const token = await getValidToken();
        
        // 测试用户权限
        await testUserPermissions(token);
        
        // 测试评审查询
        await testSimpleReviewQuery(token);
        
    } catch (error) {
        console.error('❌ 调试过程中发生错误:', error.message);
    }
}
 
// 运行主函数
if (require.main === module) {
    main();
}
 
module.exports = { getValidToken, testUserPermissions, testSimpleReviewQuery };