Codex Assistant
昨天 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
const axios = require('axios');
 
// 配置
const BASE_URL = 'http://localhost:8080/api';
 
// 使用一个之前获取的有效token(用户需要替换)
const EXISTING_TOKEN = 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNzM3NTM5NzU5LCJleHAiOjE3Mzc1NDY5NTl9.Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8'; // 请替换为实际的token
 
// 调试用户信息的GraphQL查询
const DEBUG_USER_INFO_QUERY = `
    query DebugUserInfo {
        reviewStatistics {
            unReviewedCount
            reviewedCount
            studentUnReviewedCount
        }
    }
`;
 
// 获取当前用户信息的查询
const GET_CURRENT_USER_QUERY = `
    query GetCurrentUser {
        currentUser {
            id
            name
            phone
        }
    }
`;
 
// 获取当前评委信息的查询
const GET_CURRENT_JUDGE_QUERY = `
    query GetCurrentJudge {
        currentJudgeInfo {
            judgeId
            judgeName
            title
            company
        }
    }
`;
 
// 测试单个查询的函数
async function testSingleQuery(queryName, query, token) {
    console.log(`\n=== 测试 ${queryName} ===`);
    
    try {
        const response = await axios.post(`${BASE_URL}/graphql`, {
            query: 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 (error.extensions) {
                    console.log(`     扩展信息:`, error.extensions);
                }
            });
        }
        
        if (response.data.data) {
            console.log('✅ 查询成功:');
            console.log('返回数据:', JSON.stringify(response.data.data, null, 2));
        }
        
    } catch (error) {
        console.error('❌ 请求失败:', error.response?.data || error.message);
        if (error.response?.status) {
            console.error('HTTP状态码:', error.response.status);
        }
    }
}
 
// 测试评审项目查询
async function testReviewProjectQuery(token) {
    console.log('\n=== 测试评审项目查询 ===');
    
    const 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: 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}`);
                console.log(`     详细信息:`, error);
            });
        }
        
        if (response.data.data) {
            console.log('✅ 查询成功:');
            console.log('返回数据:', JSON.stringify(response.data.data, null, 2));
        }
        
    } catch (error) {
        console.error('❌ 请求失败:', error.response?.data || error.message);
    }
}
 
// 主函数
async function main() {
    console.log('🔍 开始调试用户权限和评委身份问题...\n');
    
    if (EXISTING_TOKEN === 'eyJhbGciOiJIUzI1NiJ9.eyJzdWIiOiIxIiwiaWF0IjoxNzM3NTM5NzU5LCJleHAiOjE3Mzc1NDY5NTl9.Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8Ej8') {
        console.log('❌ 请先替换脚本中的EXISTING_TOKEN为实际的token');
        return;
    }
    
    console.log('使用Token:', EXISTING_TOKEN.substring(0, 50) + '...');
    
    // 测试各个查询
    await testSingleQuery('当前用户信息', GET_CURRENT_USER_QUERY, EXISTING_TOKEN);
    await testSingleQuery('当前评委信息', GET_CURRENT_JUDGE_QUERY, EXISTING_TOKEN);
    await testSingleQuery('评审统计', DEBUG_USER_INFO_QUERY, EXISTING_TOKEN);
    await testReviewProjectQuery(EXISTING_TOKEN);
}
 
// 运行主函数
if (require.main === module) {
    main();
}
 
module.exports = { testSingleQuery, testReviewProjectQuery };