Automatically trim values before saving
This commit is contained in:
@ -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,
|
||||
|
Reference in New Issue
Block a user