feat(utils/perm: changing return type for anyhow::Result
This commit is contained in:
parent
26d8f6c902
commit
5c2ff8b926
1 changed files with 17 additions and 15 deletions
|
|
@ -1,9 +1,11 @@
|
||||||
|
use anyhow::Result;
|
||||||
use sqlx::{
|
use sqlx::{
|
||||||
PgPool,
|
PgPool,
|
||||||
query_scalar,
|
query_scalar,
|
||||||
};
|
};
|
||||||
|
use tracing::warn;
|
||||||
|
|
||||||
pub async fn is_whitelist(db: &PgPool, user_id: &str, guild_id: &str) -> Result<bool, sqlx::Error> {
|
pub async fn is_whitelist(db: &PgPool, user_id: &str, guild_id: &str) -> Result<bool> {
|
||||||
let result: Option<bool> = query_scalar(
|
let result: Option<bool> = query_scalar(
|
||||||
"SELECT TRUE FROM guild_users gu \
|
"SELECT TRUE FROM guild_users gu \
|
||||||
LEFT JOIN users u ON u.user_id = gu.user_id \
|
LEFT JOIN users u ON u.user_id = gu.user_id \
|
||||||
|
|
@ -22,9 +24,19 @@ pub async fn is_whitelist(db: &PgPool, user_id: &str, guild_id: &str) -> Result<
|
||||||
Ok(result.is_some())
|
Ok(result.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_owner(db: &PgPool, user_id: &str) -> Result<bool, sqlx::Error> {
|
pub async fn is_owner(db: &PgPool, user_id: &str) -> Result<bool> {
|
||||||
|
let result: bool = query_scalar(
|
||||||
|
"SELECT is_dev, is_buyer, is_owner FROM users WHERE user_id = $1 AND (is_dev = true OR is_buyer = true OR is_owner = true)",
|
||||||
|
)
|
||||||
|
.bind(user_id)
|
||||||
|
.fetch_one(db)
|
||||||
|
.await?;
|
||||||
|
Ok(result)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn is_buyer(db: &PgPool, user_id: &str) -> Result<bool> {
|
||||||
let result: Option<bool> = query_scalar(
|
let result: Option<bool> = query_scalar(
|
||||||
"SELECT TRUE FROM users WHERE user_id = $1 AND is_dev = true OR is_buyer = true OR is_owner = true",
|
"SELECT is_dev, is_buyer FROM users WHERE user_id = $1 AND (is_dev = true OR is_buyer = true)",
|
||||||
)
|
)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
|
|
@ -32,19 +44,9 @@ pub async fn is_owner(db: &PgPool, user_id: &str) -> Result<bool, sqlx::Error> {
|
||||||
Ok(result.is_some())
|
Ok(result.is_some())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn is_buyer(db: &PgPool, user_id: &str) -> Result<bool, sqlx::Error> {
|
pub async fn is_dev(db: &PgPool, user_id: &str) -> Result<bool> {
|
||||||
let result: Option<bool> = query_scalar(
|
let result: Option<bool> = query_scalar(
|
||||||
"SELECT TRUE FROM users WHERE user_id = $1 AND is_dev = true OR is_buyer = true",
|
"SELECT is_dev FROM users WHERE user_id = $1 AND is_dev = true",
|
||||||
)
|
|
||||||
.bind(user_id)
|
|
||||||
.fetch_optional(db)
|
|
||||||
.await?;
|
|
||||||
Ok(result.is_some())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn is_dev(db: &PgPool, user_id: &str) -> Result<bool, sqlx::Error> {
|
|
||||||
let result: Option<bool> = query_scalar(
|
|
||||||
"SELECT TRUE FROM users WHERE user_id = $1 AND is_dev = true",
|
|
||||||
)
|
)
|
||||||
.bind(user_id)
|
.bind(user_id)
|
||||||
.fetch_optional(db)
|
.fetch_optional(db)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue