Lines
100 %
Functions
50 %
Branches
//! `(merge-accounts "into-uuid" "from-uuid")`: UUIDs only.
use uuid::Uuid;
use crate::forms::merge_accounts;
use crate::natives::forms::{args_error, native_failure};
fn account_id(role: &str, text: Option<String>) -> wasmtime::Result<Uuid> {
let text = text.unwrap_or_default();
Uuid::parse_str(text.trim()).map_err(|_| {
args_error(format!(
"merge-accounts: {role} must be an account UUID, got '{text}'"
))
})
}
pub(super) async fn run_merge_accounts(
user_id: Uuid,
into: Option<String>,
from: Option<String>,
) -> wasmtime::Result<String> {
let into = account_id("into", into)?;
let from = account_id("from", from)?;
merge_accounts(user_id, into, from)
.await
.map(|merged| merged.into.to_string())
.map_err(native_failure)