Lines
100 %
Functions
18.75 %
Branches
use crate::command::connection;
use finance::tag::normalize;
use sqlx::types::Uuid;
use supp_macro::command;
use super::attempt::settled;
use super::{CmdError, CmdResult};
use crate::attempt::Tries;
use crate::{tag::owned::Owner, user::User};
pub(super) fn not_found() -> CmdError {
CmdError::NotFound("Account not found".to_string())
}
command! {
ClearAccountTag {
#[required]
user_id: Uuid,
account_id: Uuid,
tag_name: String,
} => {
let (tag_name, _) = normalize(&tag_name, "");
if tag_name.is_empty() {
return Err(CmdError::Args("Tag name must not be blank".to_string()));
if tag_name == "name" {
return Err(CmdError::Args("The name tag cannot be cleared".to_string()));
let user = User { id: user_id };
let mut conn = connection(&user).await?;
let mut tries = Tries::default();
while tries
.step(settled(Owner::Account.clear(&mut conn, account_id, tag_name).await, not_found))?
.is_none()
{}
Ok(Some(CmdResult::String("ok".to_string())))