Refactor notification handling in Workers: Centralize notification insertion and frontend updates by replacing direct SQL queries with dedicated functions. This improves code maintainability and reduces redundancy across character creation, events, and transport processing.
This commit is contained in:
@@ -13,8 +13,8 @@ use crate::worker::sql::{
|
||||
QUERY_DELETE_PRODUCTION,
|
||||
QUERY_INSERT_INVENTORY,
|
||||
QUERY_INSERT_UPDATE_PRODUCTION_LOG,
|
||||
QUERY_ADD_OVERPRODUCTION_NOTIFICATION,
|
||||
};
|
||||
use crate::worker::insert_notification_conn;
|
||||
|
||||
/// Abbildet eine abgeschlossene Produktion aus der Datenbank.
|
||||
#[derive(Debug, Clone)]
|
||||
@@ -402,22 +402,13 @@ impl ProduceWorker {
|
||||
.get()
|
||||
.map_err(|e| crate::db::DbError::new(format!("DB-Verbindung fehlgeschlagen: {e}")))?;
|
||||
|
||||
conn.prepare(
|
||||
"add_overproduction_notification",
|
||||
QUERY_ADD_OVERPRODUCTION_NOTIFICATION,
|
||||
)?;
|
||||
|
||||
// Zusätzlich zur Menge die Branch-ID in der Payload mitschicken, damit
|
||||
// das Frontend die Überproduktion einem konkreten Branch zuordnen kann.
|
||||
let notification = format!(
|
||||
r#"{{"tr":"production.overproduction","value":{},"branch_id":{}}}"#,
|
||||
remaining_quantity, branch_id
|
||||
);
|
||||
|
||||
conn.execute(
|
||||
"add_overproduction_notification",
|
||||
&[&user_id, ¬ification],
|
||||
)?;
|
||||
insert_notification_conn(&mut conn, user_id, ¬ification, None)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user