mirror of
https://github.com/fawney19/Aether.git
synced 2026-09-01 17:00:21 +08:00
fix(wallet): 删除与过期删除 API Key 时同步禁用关联钱包 (#315)
- 在 delete_user_api_key 和 delete_standalone_api_key 事务中,先将关联 wallets.status 更新为 disabled - 在过期 Key 自动清理流程中,删除前同步禁用对应钱包 - 保留 wallet 与交易流水,避免出现 orphaned 且 active 的钱包状态
This commit is contained in:
@@ -656,6 +656,14 @@ SET api_key_id = NULL
|
||||
WHERE api_key_id = $1
|
||||
"#;
|
||||
|
||||
const DISABLE_WALLET_BY_API_KEY_ID_SQL: &str = r#"
|
||||
UPDATE wallets
|
||||
SET status = 'disabled',
|
||||
updated_at = NOW()
|
||||
WHERE api_key_id = $1
|
||||
AND status <> 'disabled'
|
||||
"#;
|
||||
|
||||
const DELETE_USER_API_KEY_SQL: &str = r#"
|
||||
DELETE FROM api_keys
|
||||
WHERE user_id = $1
|
||||
@@ -1268,6 +1276,11 @@ impl AuthApiKeyWriteRepository for SqlxAuthApiKeySnapshotReadRepository {
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_postgres_err()?;
|
||||
sqlx::query(DISABLE_WALLET_BY_API_KEY_ID_SQL)
|
||||
.bind(api_key_id)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_postgres_err()?;
|
||||
let result = sqlx::query(DELETE_USER_API_KEY_SQL)
|
||||
.bind(user_id)
|
||||
.bind(api_key_id)
|
||||
@@ -1290,6 +1303,11 @@ impl AuthApiKeyWriteRepository for SqlxAuthApiKeySnapshotReadRepository {
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_postgres_err()?;
|
||||
sqlx::query(DISABLE_WALLET_BY_API_KEY_ID_SQL)
|
||||
.bind(api_key_id)
|
||||
.execute(&mut *tx)
|
||||
.await
|
||||
.map_postgres_err()?;
|
||||
let result = sqlx::query(DELETE_STANDALONE_API_KEY_SQL)
|
||||
.bind(api_key_id)
|
||||
.execute(&mut *tx)
|
||||
|
||||
Reference in New Issue
Block a user