From 746c851cd555e2f46378617330696ea46ebe4285 Mon Sep 17 00:00:00 2001 From: Neo Sun Date: Wed, 15 Oct 2025 22:42:12 +1300 Subject: [PATCH] Support re-build the customer pay accounts when crash --- api/src/models/customer.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/api/src/models/customer.rs b/api/src/models/customer.rs index 8211b9d..96b1d32 100644 --- a/api/src/models/customer.rs +++ b/api/src/models/customer.rs @@ -31,7 +31,16 @@ impl Customer { /// get or insert the account by given account pub async fn get_or_insert(account: String, db: &PgPool, mem: &str) -> Result { - if let Ok(a) = Self::get_by_account(&account, db).await { + if let Ok(mut a) = Self::get_by_account(&account, db).await { + // check customer has pay account + if a.eth.is_empty() { + let (_, eth) = generate_eth(0, a.id, mem).map_err(|_err| ApiError::Internal)?; + a.eth = eth; + let _ = query!("UPDATE customers SET eth=$1 WHERE id=$2", a.eth, a.id) + .execute(db) + .await?; + } + Ok(a) } else { let now = Utc::now().naive_utc();