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 };
|