feat: additionnal bal features: ended field, current_bal for users
This commit is contained in:
parent
61aac4bd80
commit
4d451ace79
5 changed files with 97 additions and 49 deletions
|
|
@ -61,27 +61,29 @@ pub async fn manage_users(db: Arc<DatabaseConnection>) {
|
|||
.with_validator(min_length!(10))
|
||||
.with_display_mode(inquire::PasswordDisplayMode::Masked)
|
||||
.prompt().unwrap();
|
||||
let new_user = user::ActiveModel {
|
||||
let mut new_user = user::ActiveModel {
|
||||
id: NotSet,
|
||||
username: Set(username),
|
||||
hashed_password: Set(hash_password(password)),
|
||||
current_bal_id: Set(None)
|
||||
current_bal_id: Set(None),
|
||||
owner_id: Set(None)
|
||||
};
|
||||
let res = new_user.insert(db.as_ref()).await.unwrap();
|
||||
let res = new_user.clone().insert(db.as_ref()).await.unwrap();
|
||||
|
||||
if Confirm::new("Add an owner corresponding to this user ?").with_default(true).prompt().is_ok_and(|choice| choice==true) {
|
||||
let first_name = prompt_text("First Name: ").unwrap();
|
||||
let last_name = prompt_text("Last Name: ").unwrap();
|
||||
let contact = prompt_text("Contact: ").unwrap();
|
||||
let new_owner = owner::ActiveModel {
|
||||
id: NotSet,
|
||||
user_id: Set(res.id),
|
||||
first_name: Set(first_name),
|
||||
last_name: Set(last_name),
|
||||
contact: Set(contact)
|
||||
};
|
||||
let _ = new_owner.insert(db.as_ref()).await.unwrap();
|
||||
}
|
||||
println!("Create corresponding owner:");
|
||||
let first_name = prompt_text("First Name: ").unwrap();
|
||||
let last_name = prompt_text("Last Name: ").unwrap();
|
||||
let contact = prompt_text("Contact: ").unwrap();
|
||||
let new_owner = owner::ActiveModel {
|
||||
id: NotSet,
|
||||
user_id: Set(res.id),
|
||||
first_name: Set(first_name),
|
||||
last_name: Set(last_name),
|
||||
contact: Set(contact)
|
||||
};
|
||||
let owner_res = new_owner.insert(db.as_ref()).await.unwrap();
|
||||
new_user.owner_id = Set(Some(owner_res.id));
|
||||
let _ = new_user.update(db.as_ref());
|
||||
}
|
||||
},
|
||||
Action::Delete => {
|
||||
|
|
|
|||
Reference in a new issue