Files
nxxmdata/government-backend/check-controller-model.js

77 lines
2.7 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 清除模块缓存
function clearModuleCache() {
const modulesToClear = Object.keys(require.cache).filter(key =>
key.includes('HarmlessPlace') || key.includes('database') || key.includes('controller')
);
console.log('清除以下模块的缓存:', modulesToClear.length, '个模块');
modulesToClear.forEach(key => {
console.log('-', key);
delete require.cache[key];
});
}
// 清除缓存后再导入
clearModuleCache();
// 直接导入HarmlessPlace模型和控制器
const HarmlessPlace = require('./models/HarmlessPlace');
const harmlessPlaceController = require('./controllers/HarmlessPlaceController');
// 检查直接导入的HarmlessPlace模型
console.log('=== 直接导入的HarmlessPlace模型 ===');
console.log('类型:', typeof HarmlessPlace);
console.log('是否有findAndCountAll方法:', typeof HarmlessPlace.findAndCountAll !== 'undefined');
if (HarmlessPlace.findAndCountAll) {
console.log('findAndCountAll的类型:', typeof HarmlessPlace.findAndCountAll);
}
// 检查控制器中的getList函数
console.log('\n=== 检查控制器的getList函数 ===');
console.log('getList的类型:', typeof harmlessPlaceController.getList);
// 分析控制器中如何使用HarmlessPlace模型
// 我们需要查看控制器的源代码
const fs = require('fs');
const path = require('path');
console.log('\n=== 查看控制器的源代码 ===');
const controllerPath = path.join(__dirname, 'controllers', 'HarmlessPlaceController.js');
const controllerContent = fs.readFileSync(controllerPath, 'utf8');
// 查找导入语句
const importStatementMatch = controllerContent.match(/require\(['"]\.\.?\/models\/[^'"]+['"]\)/g);
console.log('控制器中的导入语句:', importStatementMatch || '未找到');
// 查找HarmlessPlace的使用
const harmlessPlaceUsage = controllerContent.match(/HarmlessPlace\.\w+/g);
console.log('控制器中HarmlessPlace的使用:', harmlessPlaceUsage || '未找到');
console.log('\n=== 检查控制器中实际使用的HarmlessPlace ===');
// 创建一个模拟的req和res对象
const mockReq = {
query: {
page: 1,
pageSize: 10
}
};
const mockRes = {
json: function(data) {
console.log('res.json被调用:', data);
},
status: function(code) {
console.log('res.status被调用:', code);
return this;
}
};
// 尝试从控制器中获取实际使用的HarmlessPlace模型
// 我们需要查看控制器的导入方式
const controllerModule = require('./controllers/HarmlessPlaceController');
// 如果控制器导出了其使用的模型,我们可以检查
// 但通常控制器不会导出这种依赖
console.log('控制器模块导出:', Object.keys(controllerModule));
console.log('\n所有检查完成');