This commit is contained in:
mykola2312 2024-03-08 08:35:23 +02:00
parent eb32b488da
commit 6a873305d9
4 changed files with 11 additions and 10 deletions

View file

@ -19,7 +19,7 @@ macro_rules! reply_i18n_and_return {
#[macro_export]
macro_rules! parse_integer {
($bot:expr, $chat_id:expr, $integer:expr) => {{
let out: i64 = match $integer.parse() {
let out: i32 = match $integer.parse() {
Ok(integer) => integer,
Err(_) => {
$bot.send_message($chat_id, t!("not_valid_integer")).await?;

View file

@ -36,7 +36,7 @@ pub async fn cmd_request(bot: Bot, msg: Message, text: String, db: DbPool) -> Ha
sqlx::query(r#"INSERT INTO "request" (requested_by,message,is_approved) VALUES ($1,$2,$3);"#)
.bind(user.id)
.bind(text)
.bind(0)
.bind(false)
.execute(&db)
.await?;
event!(Level::INFO, "added request for {}", user);
@ -95,7 +95,7 @@ pub async fn cmd_listrequests(bot: Bot, msg: Message, db: DbPool) -> HandlerResu
}
pub async fn cmd_approve(bot: Bot, msg: Message, id: String, db: DbPool) -> HandlerResult {
let id: i64 = parse_integer!(bot, msg.chat.id, id);
let id: i32 = parse_integer!(bot, msg.chat.id, id);
if let Some(user) = msg.from() {
let user = find_or_create_user(&db, user).await?;
@ -108,7 +108,7 @@ pub async fn cmd_approve(bot: Bot, msg: Message, id: String, db: DbPool) -> Hand
r#"SELECT "request".id AS request_id, "request".message, "user".*
FROM "request"
INNER JOIN "user" ON "request".requested_by = "user".id
WHERE request_id = $1 AND "request".is_approved = false
WHERE "request".id = $1 AND "request".is_approved = false
LIMIT 1;"#,
)
.bind(id)
@ -156,7 +156,7 @@ pub async fn cmd_approve(bot: Bot, msg: Message, id: String, db: DbPool) -> Hand
}
pub async fn cmd_decline(bot: Bot, msg: Message, id: String, db: DbPool) -> HandlerResult {
let id: i64 = parse_integer!(bot, msg.chat.id, id);
let id: i32 = parse_integer!(bot, msg.chat.id, id);
if let Some(user) = msg.from() {
let user = find_or_create_user(&db, user).await?;
@ -169,7 +169,7 @@ pub async fn cmd_decline(bot: Bot, msg: Message, id: String, db: DbPool) -> Hand
r#"SELECT "request".id AS request_id, "request".message, "user".*
FROM "request"
INNER JOIN "user" ON "request".requested_by = "user".id
WHERE request_id = $1 AND "request".is_approved = false
WHERE "request".id = $1 AND "request".is_approved = false
LIMIT 1;"#,
)
.bind(id)

View file

@ -41,7 +41,7 @@ pub async fn cmd_request_chat(bot: Bot, msg: Message, text: String, db: DbPool)
.bind(user.id)
.bind(chat.id)
.bind(text)
.bind(0)
.bind(false)
.execute(&db)
.await?;
event!(Level::INFO, "added chat request for {}", chat);
@ -101,7 +101,7 @@ pub async fn cmd_listrequests_chat(bot: Bot, msg: Message, db: DbPool) -> Handle
}
pub async fn cmd_approve_chat(bot: Bot, msg: Message, id: String, db: DbPool) -> HandlerResult {
let id: i64 = parse_integer!(bot, msg.chat.id, id);
let id: i32 = parse_integer!(bot, msg.chat.id, id);
if let Some(user) = msg.from() {
let user = find_or_create_user(&db, user).await?;
@ -110,6 +110,7 @@ pub async fn cmd_approve_chat(bot: Bot, msg: Message, id: String, db: DbPool) ->
}
// get request
// BUG: FIX SQL
let res: Result<RequestChatWithChat, sqlx::Error> = sqlx::query_as(
r#"SELECT "request_chat".id AS request_id, "request_chat".message, "chat".*
FROM "request_chat"
@ -157,7 +158,7 @@ pub async fn cmd_approve_chat(bot: Bot, msg: Message, id: String, db: DbPool) ->
}
pub async fn cmd_decline_chat(bot: Bot, msg: Message, id: String, db: DbPool) -> HandlerResult {
let id: i64 = parse_integer!(bot, msg.chat.id, id);
let id: i32 = parse_integer!(bot, msg.chat.id, id);
if let Some(user) = msg.from() {
let user = find_or_create_user(&db, user).await?;

View file

@ -15,7 +15,7 @@ pub async fn create_user(db: &DbPool, user: &types::User) -> Result<User, sqlx::
.bind(&user.last_name)
.bind(false)
.bind(false)
.bind(0)
.bind(false)
.execute(db)
.await?;