Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Prorations #975

Merged
merged 6 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

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

16 changes: 16 additions & 0 deletions src/database/models/charge_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,22 @@ impl ChargeItem {
.collect::<Result<Vec<_>, serde_json::Error>>()?)
}

pub async fn get_unprovision(
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<ChargeItem>, DatabaseError> {
let now = Utc::now();

let res =
select_charges_with_predicate!("WHERE (status = 'cancelled' AND due < $1) OR (status = 'failed' AND last_attempt < $1 - INTERVAL '2 days')", now)
.fetch_all(exec)
.await?;

Ok(res
.into_iter()
.map(|r| r.try_into())
.collect::<Result<Vec<_>, serde_json::Error>>()?)
}

pub async fn remove(
id: ChargeId,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
Expand Down
24 changes: 0 additions & 24 deletions src/database/models/user_subscription_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,30 +95,6 @@ impl UserSubscriptionItem {
.collect::<Result<Vec<_>, serde_json::Error>>()?)
}

pub async fn get_all_unprovision(
exec: impl sqlx::Executor<'_, Database = sqlx::Postgres>,
) -> Result<Vec<UserSubscriptionItem>, DatabaseError> {
let now = Utc::now();
let results = select_user_subscriptions_with_predicate!(
"
INNER JOIN charges c
ON c.subscription_id = us.id
AND (
(c.status = 'cancelled' AND c.due < $1) OR
(c.status = 'failed' AND c.last_attempt < $1 - INTERVAL '2 days')
)
",
now
)
.fetch_all(exec)
.await?;

Ok(results
.into_iter()
.map(|r| r.try_into())
.collect::<Result<Vec<_>, serde_json::Error>>()?)
}

pub async fn upsert(
&self,
transaction: &mut sqlx::Transaction<'_, sqlx::Postgres>,
Expand Down
12 changes: 10 additions & 2 deletions src/models/v3/billing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ pub struct Product {
#[serde(tag = "type", rename_all = "kebab-case")]
pub enum ProductMetadata {
Midas,
Pyro { ram: u32 },
Pyro {
cpu: u32,
ram: u32,
swap: u32,
storage: u32,
},
}

#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand Down Expand Up @@ -70,13 +75,16 @@ impl PriceDuration {
_ => PriceDuration::Monthly,
}
}

pub fn as_str(&self) -> &'static str {
match self {
PriceDuration::Monthly => "monthly",
PriceDuration::Yearly => "yearly",
}
}

pub fn iterator() -> impl Iterator<Item = PriceDuration> {
vec![PriceDuration::Monthly, PriceDuration::Yearly].into_iter()
}
}

#[derive(Copy, Clone, PartialEq, Eq, Serialize, Deserialize, Debug)]
Expand Down
Loading
Loading