Automatically trim values before saving

This commit is contained in:
2023-08-31 19:23:21 +02:00
parent 0899835fab
commit 2a69c89065
2 changed files with 43 additions and 1 deletions

View File

@ -103,8 +103,29 @@ fn check_opt_str_val(
Ok(())
}
fn trim_opt_val(val: &mut Option<String>) {
if let Some(s) = val {
*val = Some(s.trim().to_string());
}
if val.as_deref() == Some("") {
*val = None;
}
}
impl MemberRequest {
pub async fn to_member(self, member: &mut Member) -> anyhow::Result<()> {
pub async fn to_member(mut self, member: &mut Member) -> anyhow::Result<()> {
// Trim values before processing
trim_opt_val(&mut self.first_name);
trim_opt_val(&mut self.last_name);
trim_opt_val(&mut self.birth_last_name);
trim_opt_val(&mut self.email);
trim_opt_val(&mut self.country);
trim_opt_val(&mut self.address);
trim_opt_val(&mut self.city);
trim_opt_val(&mut self.note);
trim_opt_val(&mut self.phone);
let c = StaticConstraints::default();
check_opt_str_val(
&self.first_name,