diff --git a/apps/labrinth/.sqlx/query-3c128a131baef8c8b18dd85a02aeca9658b604b3f3eab53fbac5fa0d95560a1c.json b/apps/labrinth/.sqlx/query-0e722c03740252645acea786fae2e9a3e406cc58059d0c21dc95ed8b5d0634d9.json similarity index 91% rename from apps/labrinth/.sqlx/query-3c128a131baef8c8b18dd85a02aeca9658b604b3f3eab53fbac5fa0d95560a1c.json rename to apps/labrinth/.sqlx/query-0e722c03740252645acea786fae2e9a3e406cc58059d0c21dc95ed8b5d0634d9.json index 8b8b97a5f..c84cc2d12 100644 --- a/apps/labrinth/.sqlx/query-3c128a131baef8c8b18dd85a02aeca9658b604b3f3eab53fbac5fa0d95560a1c.json +++ b/apps/labrinth/.sqlx/query-0e722c03740252645acea786fae2e9a3e406cc58059d0c21dc95ed8b5d0634d9.json @@ -1,6 +1,6 @@ { "db_name": "PostgreSQL", - "query": "\n SELECT\n us.id, us.user_id, us.price_id, us.interval, us.created, us.status, us.metadata\n FROM users_subscriptions us\n \n INNER JOIN products_prices pp ON us.price_id = pp.id\n INNER JOIN products p ON p.metadata @> '{\"type\": \"pyro\"}'\n WHERE $1::text IS NULL OR us.status = $1::text\n ", + "query": "\n SELECT\n us.id, us.user_id, us.price_id, us.interval, us.created, us.status, us.metadata\n FROM users_subscriptions us\n \n INNER JOIN products_prices pp ON us.price_id = pp.id\n INNER JOIN products p ON p.metadata @> '{\"type\": \"pyro\"}'\n WHERE $1::text IS NULL OR us.status = $1::text\n GROUP BY us.id\n ", "describe": { "columns": [ { @@ -54,5 +54,5 @@ true ] }, - "hash": "3c128a131baef8c8b18dd85a02aeca9658b604b3f3eab53fbac5fa0d95560a1c" + "hash": "0e722c03740252645acea786fae2e9a3e406cc58059d0c21dc95ed8b5d0634d9" } diff --git a/apps/labrinth/src/database/models/user_subscription_item.rs b/apps/labrinth/src/database/models/user_subscription_item.rs index ed6e6507f..0cdd6785a 100644 --- a/apps/labrinth/src/database/models/user_subscription_item.rs +++ b/apps/labrinth/src/database/models/user_subscription_item.rs @@ -115,6 +115,7 @@ impl UserSubscriptionItem { INNER JOIN products_prices pp ON us.price_id = pp.id INNER JOIN products p ON p.metadata @> '{"type": "pyro"}' WHERE $1::text IS NULL OR us.status = $1::text + GROUP BY us.id "#, status ) diff --git a/apps/labrinth/src/routes/internal/billing.rs b/apps/labrinth/src/routes/internal/billing.rs index 03165a617..38a130c59 100644 --- a/apps/labrinth/src/routes/internal/billing.rs +++ b/apps/labrinth/src/routes/internal/billing.rs @@ -898,14 +898,25 @@ pub async fn active_servers( ) .await?; + #[derive(Serialize)] + struct ActiveServer { + pub user_id: crate::models::ids::UserId, + pub server_id: String, + pub interval: PriceDuration, + } + let server_ids = servers .into_iter() .filter_map(|x| { - x.metadata.map(|x| match x { - SubscriptionMetadata::Pyro { id } => id, + x.metadata.as_ref().map(|metadata| match metadata { + SubscriptionMetadata::Pyro { id } => ActiveServer { + user_id: x.user_id.into(), + server_id: id.clone(), + interval: x.interval, + }, }) }) - .collect::>(); + .collect::>(); Ok(HttpResponse::Ok().json(server_ids)) } @@ -1747,7 +1758,7 @@ pub async fn stripe_webhook( "source": source, "payment_interval": metadata.charge_item.subscription_interval.map(|x| match x { PriceDuration::Monthly => 1, - PriceDuration::Yearly => 3, + PriceDuration::Yearly => 12, }) })) .send()