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

@@ -1009,6 +1009,23 @@ impl EventsWorker {
conn.prepare("update_money_event", QUERY_UPDATE_MONEY)?;
let _ = conn.execute("update_money_event", &[&user_id, &change, &action])?;
// Best-effort money_history insert for UI/history visibility.
let money_str = format!("{:.2}", 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 = user_id,
money = money_str,
act = escaped_action
);
if let Err(err) = conn.query(&history_sql) {
eprintln!(
"[EventsWorker] Warning: inserting money_history failed for user {}: {}",
user_id, err
);
}
Ok(change)
}