Skip to content

Commit

Permalink
Update servers route (#3032)
Browse files Browse the repository at this point in the history
  • Loading branch information
Geometrically authored Dec 17, 2024
1 parent fee8d6c commit 7e8cead
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
19 changes: 15 additions & 4 deletions apps/labrinth/src/routes/internal/billing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Vec<_>>();
.collect::<Vec<ActiveServer>>();

Ok(HttpResponse::Ok().json(server_ids))
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 7e8cead

Please sign in to comment.