fix(companies): restore backend build

This commit is contained in:
Ashwin Kumar Sivakumar 2026-06-14 06:08:00 +05:30
parent 349673b7f8
commit 9b3bc98b38
3 changed files with 24 additions and 24 deletions

1
Cargo.lock generated
View file

@ -804,6 +804,7 @@ dependencies = [
"db",
"email",
"redis",
"reqwest",
"serde",
"serde_json",
"sqlx",

View file

@ -21,4 +21,5 @@ storage = { path = "../../crates/storage" }
bytes = { workspace = true }
cache = { path = "../../crates/cache" }
redis = { workspace = true }
reqwest = { workspace = true }

View file

@ -1,6 +1,6 @@
use crate::AppState;
use axum::{
extract::{Path, Query, State},
extract::{Query, State},
http::StatusCode,
response::IntoResponse,
routing::{get, post},
@ -88,15 +88,14 @@ async fn get_ai_credits(
(StatusCode::BAD_REQUEST, "Invalid company ID".to_string())
})?;
let credits = sqlx::query_as!(
CompanyAICredits,
let credits = sqlx::query_as::<_, CompanyAICredits>(
r#"
SELECT company_id, credits_balance, updated_at
FROM company_ai_credits
WHERE company_id = $1
"#,
company_id
)
.bind(company_id)
.fetch_optional(&state.pool)
.await
.map_err(|e| {
@ -136,15 +135,15 @@ async fn generate_ai(
);
// Check credits
let credits = sqlx::query_scalar!(
let credits = sqlx::query_scalar::<_, i32>(
r#"
SELECT credits_balance
FROM company_ai_credits
WHERE company_id = $1
FOR UPDATE
"#,
company_id
)
.bind(company_id)
.fetch_optional(&state.pool)
.await
.map_err(|e| {
@ -159,7 +158,7 @@ async fn generate_ai(
}
// Deduct credit
sqlx::query!(
sqlx::query(
r#"
UPDATE company_ai_credits
SET credits_balance = credits_balance - 1,
@ -167,8 +166,8 @@ async fn generate_ai(
WHERE company_id = $1
RETURNING credits_balance
"#,
company_id
)
.bind(company_id)
.fetch_one(&state.pool)
.await
.map_err(|e| {
@ -181,20 +180,20 @@ async fn generate_ai(
let prompt_preview = request.prompt.chars().take(100).collect::<String>();
let result_preview = "AI generated response".chars().take(100).collect::<String>();
sqlx::query!(
sqlx::query(
r#"
INSERT INTO ai_usage_log (id, company_id, request_type, credits_used, prompt_preview, result_preview, model_used, status, created_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, NOW())
"#,
request_id,
company_id,
request.request_type,
1_i32,
prompt_preview,
result_preview,
"gemma3:270m",
"success"
)
.bind(request_id)
.bind(company_id)
.bind(&request.request_type)
.bind(1_i32)
.bind(prompt_preview)
.bind(result_preview)
.bind("gemma3:270m")
.bind("success")
.execute(&state.pool)
.await
.map_err(|e| {
@ -242,12 +241,12 @@ async fn get_usage_history(
let offset = (page - 1) * per_page;
// Get total count
let total = sqlx::query_scalar!(
let total = sqlx::query_scalar::<_, i64>(
r#"
SELECT COUNT(*) FROM ai_usage_log WHERE company_id = $1
"#,
company_id
)
.bind(company_id)
.fetch_one(&state.pool)
.await
.map_err(|e| {
@ -256,8 +255,7 @@ async fn get_usage_history(
}).unwrap_or(0);
// Get entries
let entries = sqlx::query_as!(
UsageEntry,
let entries = sqlx::query_as::<_, UsageEntry>(
r#"
SELECT id, request_type, credits_used, prompt_preview, result_preview,
model_used, status, error_message, created_at
@ -266,10 +264,10 @@ async fn get_usage_history(
ORDER BY created_at DESC
LIMIT $2 OFFSET $3
"#,
company_id,
per_page,
offset
)
.bind(company_id)
.bind(per_page)
.bind(offset)
.fetch_all(&state.pool)
.await
.map_err(|e| {