From 2833d9850bb92b9332c79a683058958fcf8153c8 Mon Sep 17 00:00:00 2001 From: EETagent Date: Sat, 5 Nov 2022 17:01:36 +0100 Subject: [PATCH] feat: parent mutation --- core/src/database/mutation/mod.rs | 3 ++- core/src/database/mutation/parent.rs | 36 ++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 core/src/database/mutation/parent.rs 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 + } +}