//! # Users service use crate::db_connection; use crate::models::{NewUser, User}; use crate::schema::users; use crate::utils::time_utils::time; use diesel::prelude::*; /// Create a new account pub async fn create_account(name: &str, email: &str) -> anyhow::Result { db_connection::execute(|conn| { let res = diesel::insert_into(users::table) .values(&NewUser { name: name.trim(), email: email.trim(), time_create: time() as i64, }) .get_result(conn)?; Ok(res) }) } /// Check if an email address is already associated with an account pub async fn exists_email(email: &str) -> anyhow::Result { db_connection::execute(|conn| { let count: i64 = users::table .filter(users::email.eq(email)) .count() .get_result(conn)?; Ok(count != 0) }) }