diff --git a/src/main.rs b/src/main.rs index 252cf9d..6487049 100644 --- a/src/main.rs +++ b/src/main.rs @@ -235,6 +235,10 @@ mod tests { usr.username, returned_usr.username, "Usernames do not match" ); + assert!( + !returned_usr.date_created.is_empty(), + "Date Created is empty" + ); } Err(err) => { assert!(false, "Error: {:?}", err.to_string()); diff --git a/src/repo/mod.rs b/src/repo/mod.rs index 17a544f..7f3ce8f 100644 --- a/src/repo/mod.rs +++ b/src/repo/mod.rs @@ -1,12 +1,8 @@ pub mod user { - // use crate::models; - // use serde::Serialize; - #[derive(Debug, serde::Serialize, sqlx::FromRow)] pub struct InsertedData { pub id: uuid::Uuid, pub date_created: Option, - // pub email: String, } pub async fn insert( @@ -16,11 +12,11 @@ pub mod user { let result = sqlx::query_as!( InsertedData, r#" - INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status, date_created) - VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW()) + INSERT INTO "user" (username, password, email, phone, firstname, lastname, email_verified, status) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id, date_created; "#, - &user.username, // Bind the input message securely + &user.username, &user.password, &user.email, &user.phone, @@ -40,25 +36,5 @@ pub mod user { Ok(id) => Ok(id.id), Err(err) => Err(err), } - - /* - let insert_sql = "INSERT INTO \"user\" (username, password, email, phone, firstname, lastname, email_verified, status) VALUES ($1, $2, $3, $4, $5, $6, $7, $8) RETURNING id"; - - match sqlx::query_scalar(insert_sql) - .bind(&user.username) // Bind the input message securely - .bind(&user.password) - .bind(&user.email) - .bind(&user.phone) - .bind(&user.firstname) - .bind(&user.lastname) - .bind(user.email_verified) - .bind(&user.status) - .fetch_one(pool) // Execute and expect exactly ONE row with ONE column back - .await - { - Ok(o) => Ok(o), - Err(err) => Err(err), // _ => uuid::Uuid::nil(), - } - */ } }