Staff support dashboard routes (#3160)

* Staff support dashboard routes

* Fix clippy
This commit is contained in:
Jai Agrawal
2025-01-17 16:41:49 -08:00
committed by GitHub
parent d7814e115d
commit 75b357a069
9 changed files with 371 additions and 36 deletions

View File

@@ -83,12 +83,18 @@ pub async fn products(
Ok(HttpResponse::Ok().json(products))
}
#[derive(Deserialize)]
struct SubscriptionsQuery {
pub user_id: Option<crate::models::ids::UserId>,
}
#[get("subscriptions")]
pub async fn subscriptions(
req: HttpRequest,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
query: web::Query<SubscriptionsQuery>,
) -> Result<HttpResponse, ApiError> {
let user = get_user_from_headers(
&req,
@@ -102,7 +108,18 @@ pub async fn subscriptions(
let subscriptions =
user_subscription_item::UserSubscriptionItem::get_all_user(
user.id.into(),
if let Some(user_id) = query.user_id {
if user.role.is_admin() {
user_id.into()
} else {
return Err(ApiError::InvalidInput(
"You cannot see the subscriptions of other users!"
.to_string(),
));
}
} else {
user.id.into()
},
&**pool,
)
.await?
@@ -573,12 +590,18 @@ pub async fn user_customer(
Ok(HttpResponse::Ok().json(customer))
}
#[derive(Deserialize)]
pub struct ChargesQuery {
pub user_id: Option<crate::models::ids::UserId>,
}
#[get("payments")]
pub async fn charges(
req: HttpRequest,
pool: web::Data<PgPool>,
redis: web::Data<RedisPool>,
session_queue: web::Data<AuthQueue>,
query: web::Query<ChargesQuery>,
) -> Result<HttpResponse, ApiError> {
let user = get_user_from_headers(
&req,
@@ -592,7 +615,18 @@ pub async fn charges(
let charges =
crate::database::models::charge_item::ChargeItem::get_from_user(
user.id.into(),
if let Some(user_id) = query.user_id {
if user.role.is_admin() {
user_id.into()
} else {
return Err(ApiError::InvalidInput(
"You cannot see the subscriptions of other users!"
.to_string(),
));
}
} else {
user.id.into()
},
&**pool,
)
.await?;