collab: Prevent max_monthly_llm_usage_spending_in_cents
from being negative (#21768)
This PR fixes an issue where the `max_monthly_llm_usage_spending_in_cents` preference could be set to a negative value. Release Notes: - N/A
This commit is contained in:
parent
73e0d816c4
commit
bdeac79d48
1 changed files with 5 additions and 3 deletions
|
@ -102,6 +102,9 @@ async fn update_billing_preferences(
|
||||||
.await?
|
.await?
|
||||||
.ok_or_else(|| anyhow!("user not found"))?;
|
.ok_or_else(|| anyhow!("user not found"))?;
|
||||||
|
|
||||||
|
let max_monthly_llm_usage_spending_in_cents =
|
||||||
|
body.max_monthly_llm_usage_spending_in_cents.max(0);
|
||||||
|
|
||||||
let billing_preferences =
|
let billing_preferences =
|
||||||
if let Some(_billing_preferences) = app.db.get_billing_preferences(user.id).await? {
|
if let Some(_billing_preferences) = app.db.get_billing_preferences(user.id).await? {
|
||||||
app.db
|
app.db
|
||||||
|
@ -109,7 +112,7 @@ async fn update_billing_preferences(
|
||||||
user.id,
|
user.id,
|
||||||
&UpdateBillingPreferencesParams {
|
&UpdateBillingPreferencesParams {
|
||||||
max_monthly_llm_usage_spending_in_cents: ActiveValue::set(
|
max_monthly_llm_usage_spending_in_cents: ActiveValue::set(
|
||||||
body.max_monthly_llm_usage_spending_in_cents,
|
max_monthly_llm_usage_spending_in_cents,
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
@ -119,8 +122,7 @@ async fn update_billing_preferences(
|
||||||
.create_billing_preferences(
|
.create_billing_preferences(
|
||||||
user.id,
|
user.id,
|
||||||
&crate::db::CreateBillingPreferencesParams {
|
&crate::db::CreateBillingPreferencesParams {
|
||||||
max_monthly_llm_usage_spending_in_cents: body
|
max_monthly_llm_usage_spending_in_cents,
|
||||||
.max_monthly_llm_usage_spending_in_cents,
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.await?
|
.await?
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue