fix: Fix Decimal serialization in rating_service for PostgreSQL compatibility

This commit is contained in:
Your Name
2026-04-01 01:25:34 +02:00
parent 271674a9c5
commit eb8d6463c5
2 changed files with 16 additions and 12 deletions

View File

@@ -142,14 +142,14 @@ def get_tool_rating_summary(tool: str) -> dict:
return { return {
"tool": tool, "tool": tool,
"count": row["count"], "count": int(row["count"]),
"average": round(row["average"], 1), "average": round(float(row["average"]), 1),
"distribution": { "distribution": {
"5": row["star5"], "5": int(row["star5"]),
"4": row["star4"], "4": int(row["star4"]),
"3": row["star3"], "3": int(row["star3"]),
"2": row["star2"], "2": int(row["star2"]),
"1": row["star1"], "1": int(row["star1"]),
}, },
} }
@@ -170,8 +170,8 @@ def get_all_ratings_summary() -> list[dict]:
return [ return [
{ {
"tool": row["tool"], "tool": row["tool"],
"count": row["count"], "count": int(row["count"]),
"average": round(row["average"], 1), "average": round(float(row["average"]), 1),
} }
for row in rows for row in rows
] ]
@@ -189,7 +189,9 @@ def get_global_rating_summary() -> dict:
cursor = execute_query(conn, sql) cursor = execute_query(conn, sql)
row = row_to_dict(cursor.fetchone()) row = row_to_dict(cursor.fetchone())
avg = float(row["average"]) if row and row["average"] is not None else 0.0
return { return {
"rating_count": int(row["count"]) if row else 0, "rating_count": int(row["count"]) if row else 0,
"average_rating": round(row["average"], 1) if row else 0.0, "average_rating": round(avg, 1),
} }

View File

@@ -219,7 +219,7 @@ const TRANSLATIONS: Record<Lang, Record<string, string>> = {
emailLabel: 'Email', emailLabel: 'Email',
passwordLabel: 'Password', passwordLabel: 'Password',
planLabel: 'Plan', planLabel: 'Plan',
roleLabel: 'Role', roleLabel2: 'Role',
createBtn: 'Create', createBtn: 'Create',
cancelBtn: 'Cancel', cancelBtn: 'Cancel',
userCreated: 'User created successfully.', userCreated: 'User created successfully.',
@@ -388,7 +388,7 @@ const TRANSLATIONS: Record<Lang, Record<string, string>> = {
emailLabel: 'البريد الإلكتروني', emailLabel: 'البريد الإلكتروني',
passwordLabel: 'كلمة المرور', passwordLabel: 'كلمة المرور',
planLabel: 'الخطة', planLabel: 'الخطة',
roleLabel: 'الدور', roleLabel2: 'الدور',
createBtn: 'إنشاء', createBtn: 'إنشاء',
cancelBtn: 'إلغاء', cancelBtn: 'إلغاء',
userCreated: 'تم إنشاء المستخدم بنجاح.', userCreated: 'تم إنشاء المستخدم بنجاح.',
@@ -604,6 +604,8 @@ export default function InternalAdminPage() {
} }
} }
// Fix duplicate roleLabel
async function handlePlanChange(userId: number, plan: 'free' | 'pro') { async function handlePlanChange(userId: number, plan: 'free' | 'pro') {
if (!isAdmin) return; if (!isAdmin) return;
setUpdatingUserId(userId); setUpdatingUserId(userId);