fix: request first_name in user creation db function
it is required column in table
This commit is contained in:
parent
a9919a9307
commit
1006fbe5c1
@ -71,9 +71,8 @@ pub async fn secret_command_handler(
|
||||
admin_password: String,
|
||||
) -> Result<(), teloxide::RequestError> {
|
||||
println!("Admin Pass: {}", admin_password);
|
||||
let user = db
|
||||
.get_or_init_user(msg.from.clone().unwrap().id.0 as i64)
|
||||
.await;
|
||||
let tguser = msg.from.clone().unwrap();
|
||||
let user = db.get_or_init_user(tguser.id.0 as i64, &tguser.first_name).await;
|
||||
println!("MSG: {}", msg.html_text().unwrap());
|
||||
match cmd {
|
||||
SecretCommands::Secret { pass } => {
|
||||
|
||||
@ -62,7 +62,7 @@ impl DB {
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
pub async fn get_or_init_user(&mut self, userid: i64) -> User {
|
||||
pub async fn get_or_init_user(&mut self, userid: i64, firstname: &str) -> User {
|
||||
use self::schema::users::dsl::*;
|
||||
let connection = &mut self.pool.get().await.unwrap();
|
||||
|
||||
@ -76,7 +76,7 @@ impl DB {
|
||||
match user {
|
||||
Some(existing_user) => existing_user,
|
||||
None => diesel::insert_into(users)
|
||||
.values((id.eq(userid as i64), is_admin.eq(false)))
|
||||
.values((id.eq(userid as i64), is_admin.eq(false), first_name.eq(firstname)))
|
||||
.get_result(connection)
|
||||
.await
|
||||
.unwrap(),
|
||||
|
||||
11
src/main.rs
11
src/main.rs
@ -97,7 +97,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
.branch(
|
||||
Update::filter_message()
|
||||
.filter_async(async |msg: Message, mut db: DB| {
|
||||
let user = db.get_or_init_user(msg.from.unwrap().id.0 as i64).await;
|
||||
let tguser = msg.from.unwrap();
|
||||
let user = db.get_or_init_user(tguser.id.0 as i64, &tguser.first_name).await;
|
||||
user.is_admin
|
||||
})
|
||||
.enter_dialogue::<Message, PostgresStorage<Json>, State>()
|
||||
@ -248,7 +249,8 @@ fn command_handler(
|
||||
.branch(
|
||||
dptree::entry()
|
||||
.filter_async(async |msg: Message, mut db: DB| {
|
||||
let user = db.get_or_init_user(msg.from.unwrap().id.0 as i64).await;
|
||||
let tguser = msg.from.unwrap();
|
||||
let user = db.get_or_init_user(tguser.id.0 as i64, &tguser.first_name).await;
|
||||
user.is_admin
|
||||
})
|
||||
.filter_command::<AdminCommands>()
|
||||
@ -262,9 +264,8 @@ async fn user_command_handler(
|
||||
msg: Message,
|
||||
cmd: UserCommands,
|
||||
) -> Result<(), teloxide::RequestError> {
|
||||
let user = db
|
||||
.get_or_init_user(msg.from.clone().unwrap().id.0 as i64)
|
||||
.await;
|
||||
let tguser = msg.from.clone().unwrap();
|
||||
let user = db.get_or_init_user(tguser.id.0 as i64, &tguser.first_name).await;
|
||||
println!("MSG: {}", msg.html_text().unwrap());
|
||||
match cmd {
|
||||
UserCommands::Start => {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user