Admins use analysis units and questions too
CI / test (push) Successful in 1m41s
CI / build (push) Successful in 5m52s
CI / deploy (push) Skipped

They add their own units on the admin page when they need more, and
testing shows the same balance as users see. Regenerating and prompt
previews stay free.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-20 10:54:24 +00:00
co-authored by Claude Opus 5.5
parent e741f9b491
commit ac5e7fa4fd
5 changed files with 28 additions and 29 deletions
+1 -4
View File
@@ -31,7 +31,6 @@ use crate::auth::AuthUser;
use crate::credits::{self, Unit};
use crate::error::{ApiError, ApiResult};
use crate::views::{rfc3339, rfc3339_opt, sha256_hex};
use db::Role;
#[derive(Debug, Clone, sqlx::FromRow)]
/// An analysis as users see it; the model is left out on purpose (a business secret).
@@ -136,10 +135,8 @@ async fn request(
req: AnalysisRequest,
) -> ApiResult<(StatusCode, Json<Value>)> {
let language = validate_locale(state, Some(req.language.as_deref().unwrap_or(&auth.user.locale)))?;
// Admins use no unit.
let admin = auth.user.has_role(Role::Admin);
// Admins use units too (they can add more on the admin page).
let unit = match target {
_ if admin => None,
Target::Synastry { .. } => Some(Unit::Synastry),
Target::Forecast { .. } => Some(Unit::Forecast),
_ => Some(Unit::Natal),
+3 -6
View File
@@ -9,7 +9,6 @@ use axum::Json;
use axum::extract::{Path, State};
use axum::http::StatusCode;
use axum_extra::extract::WithRejection;
use db::Role;
use serde::Deserialize;
use serde_json::{Value, json};
use sqlx::PgPool;
@@ -145,7 +144,6 @@ pub async fn ask(
));
}
let admin = auth.user.has_role(Role::Admin);
let (model, fallback, prompt_version) = model_and_version(&state, &analysis.language).await?;
let question_id = Uuid::now_v7();
let mut tx = state.db.begin().await?;
@@ -161,13 +159,12 @@ pub async fn ask(
.bind(&analysis.language)
.bind(&model)
.bind(&prompt_version)
.bind(i32::from(!admin))
.bind(1i32)
.bind(&fallback)
.fetch_one(&mut *tx)
.await?;
if !admin {
credits::spend_question(&mut tx, auth.id(), question_id).await?;
}
// Admins use questions too (they can add more on the admin page).
credits::spend_question(&mut tx, auth.id(), question_id).await?;
tx.commit().await?;
Ok((StatusCode::ACCEPTED, Json(row.view())))
}