Enhance money history logging: Implement best-effort insert into money_history for UI visibility across BaseWorker, EventsWorker, and UndergroundWorker, improving tracking of monetary changes.

This commit is contained in:
Torsten Schulz (local)
2025-12-09 08:19:42 +01:00
parent e8c8c5edb1
commit d740dbbf73
3 changed files with 53 additions and 0 deletions

View File

@@ -962,6 +962,24 @@ fn change_falukant_user_money(
let p2: &(dyn ToSql + Sync) = &money_change;
let p3: &(dyn ToSql + Sync) = &action;
conn.execute("ug_update_money", &[p1, p2, p3])?;
// Best-effort insert into money_history for UI visibility
let money_str = format!("{:.2}", money_change);
fn escape_sql_literal(s: &str) -> String { s.replace('\'', "''") }
let escaped_action = escape_sql_literal(action);
let history_sql = format!(
"INSERT INTO falukant_log.money_history (user_id, change, action, created_at) VALUES ({uid}, {money}::numeric, '{act}', NOW());",
uid = falukant_user_id,
money = money_str,
act = escaped_action
);
if let Err(err) = conn.query(&history_sql) {
eprintln!(
"[UndergroundWorker] Warning: inserting money_history failed for user {}: {}",
falukant_user_id, err
);
}
Ok(())
}