fix: resolve user ID validation issue in yijing analysis

- Fixed overly strict user ID validation that rejected string IDs
- Added proper type conversion from string to integer for user IDs
- Ensured compatibility with both string and numeric user ID formats
- Prevents 'Invalid User ID' error for legitimate users
This commit is contained in:
patdelphi
2025-08-24 13:05:13 +08:00
parent 0a62208cda
commit 936f961c7d

View File

@@ -154,7 +154,9 @@ router.post('/yijing', authenticate, asyncHandler(async (req, res) => {
// 验证用户ID
const targetUserId = user_id || req.user.id;
if (!Number.isInteger(targetUserId) || targetUserId <= 0) {
const numericUserId = typeof targetUserId === 'string' ? parseInt(targetUserId, 10) : targetUserId;
if (!numericUserId || isNaN(numericUserId) || numericUserId <= 0) {
throw new AppError('用户ID无效', 400, 'INVALID_USER_ID');
}
@@ -162,7 +164,7 @@ router.post('/yijing', authenticate, asyncHandler(async (req, res) => {
// 执行易经分析(纯分析,不存储历史记录)
const analysisResult = yijingAnalyzer.performYijingAnalysis({
question: question.trim(),
user_id: targetUserId,
user_id: numericUserId,
divination_method: divination_method || 'time',
user_timezone: user_timezone,
local_time: local_time