//! Admin-action audit log writes. //! //! Insert is always called from inside the same transaction as the //! action it audits — the executor parameter is `PgExecutor` so the //! caller passes `&mut *tx` directly. use sqlx::PgExecutor; use uuid::Uuid; use crate::error::AppResult; pub async fn insert<'e, E: PgExecutor<'e>>( executor: E, actor_user_id: Uuid, action: &str, target_kind: &str, target_id: Option, payload: serde_json::Value, ) -> AppResult<()> { sqlx::query( "INSERT INTO admin_audit (actor_user_id, action, target_kind, target_id, payload) \ VALUES ($1, $2, $3, $4, $5)", ) .bind(actor_user_id) .bind(action) .bind(target_kind) .bind(target_id) .bind(payload) .execute(executor) .await?; Ok(()) }