diff --git a/core/src/database/mutation/mod.rs b/core/src/database/mutation/mod.rs index 633a325..80bf6e9 100644 --- a/core/src/database/mutation/mod.rs +++ b/core/src/database/mutation/mod.rs @@ -1,4 +1,5 @@ pub struct Mutation; pub mod session; -pub mod candidate; \ No newline at end of file +pub mod candidate; +pub mod parent; \ No newline at end of file diff --git a/core/src/database/mutation/parent.rs b/core/src/database/mutation/parent.rs new file mode 100644 index 0000000..80c7a7e --- /dev/null +++ b/core/src/database/mutation/parent.rs @@ -0,0 +1,36 @@ +use crate::Mutation; + +use ::entity::parent::{self, Model}; +use sea_orm::*; + +impl Mutation { + pub async fn create_parent(db: &DbConn, application_id: i32) -> Result { + parent::ActiveModel { + application: Set(application_id), + created_at: Set(chrono::offset::Local::now().naive_local()), + updated_at: Set(chrono::offset::Local::now().naive_local()), + ..Default::default() + } + .insert(db) + .await + } + + pub async fn add_parent_details( + db: &DbConn, + user: Model, + name: String, + surname: String, + telephone: String, + email: String, + ) -> Result { + let mut user: parent::ActiveModel = user.into(); + user.name = Set(Some(name)); + user.surname = Set(Some(surname)); + user.telephone = Set(Some(telephone)); + user.email = Set(Some(email)); + + user.updated_at = Set(chrono::offset::Local::now().naive_local()); + + user.update(db).await + } +}