From 5fa1f8f74ca9eb85da9413a13ff40fc17a5f7494 Mon Sep 17 00:00:00 2001 From: Ashwin Kumar Sivakumar Date: Fri, 10 Jul 2026 14:27:15 +0530 Subject: [PATCH] fix(profile): persist all COMPANY profile fields, not just company_name --- apps/users/src/handlers/profile.rs | 76 ++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/apps/users/src/handlers/profile.rs b/apps/users/src/handlers/profile.rs index ebf9b35..90a6f07 100644 --- a/apps/users/src/handlers/profile.rs +++ b/apps/users/src/handlers/profile.rs @@ -240,18 +240,85 @@ async fn save_profile( .and_then(|v| v.as_str()) .unwrap_or_default() .to_string(); + let email = input + .profile_data + .get("company_email") + .and_then(|v| v.as_str()) + .unwrap_or_default() + .to_string(); + let phone = input + .profile_data + .get("company_phone") + .and_then(|v| v.as_str()) + .unwrap_or_default() + .to_string(); + let website = input + .profile_data + .get("website") + .and_then(|v| v.as_str()) + .unwrap_or_default() + .to_string(); + let city = input + .profile_data + .get("location") + .and_then(|v| v.as_str()) + .unwrap_or_default() + .to_string(); + let state_val = input + .profile_data + .get("state") + .and_then(|v| v.as_str()) + .unwrap_or_default() + .to_string(); + let postal = input + .profile_data + .get("pin_code") + .and_then(|v| v.as_str()) + .unwrap_or_default() + .to_string(); + let address = input + .profile_data + .get("address") + .and_then(|v| v.as_str()) + .unwrap_or_default() + .to_string(); + let gst = input + .profile_data + .get("gst_number") + .and_then(|v| v.as_str()) + .unwrap_or_default() + .to_string(); return match sqlx::query( r#" - INSERT INTO company_profiles (user_id, company_name, status, updated_at) - VALUES ($1, $2, 'DRAFT', NOW()) + INSERT INTO company_profiles ( + user_id, company_name, contact_email, contact_phone, website_url, + address_line1, city, state, postal_code, gst_number, status, updated_at + ) + VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, 'DRAFT', NOW()) ON CONFLICT (user_id) DO UPDATE SET company_name = EXCLUDED.company_name, + contact_email = EXCLUDED.contact_email, + contact_phone = EXCLUDED.contact_phone, + website_url = EXCLUDED.website_url, + address_line1 = EXCLUDED.address_line1, + city = EXCLUDED.city, + state = EXCLUDED.state, + postal_code = EXCLUDED.postal_code, + gst_number = EXCLUDED.gst_number, updated_at = NOW() "#, ) .bind(auth.user_id) .bind(&name) + .bind(&email) + .bind(&phone) + .bind(&website) + .bind(&address) + .bind(&city) + .bind(&state_val) + .bind(&postal) + .bind(&gst) .execute(&state.pool) .await { @@ -260,7 +327,10 @@ async fn save_profile( Json(serde_json::json!({ "saved": true, "role_key": role_key })), ) .into_response(), - Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, e.to_string()).into_response(), + Err(e) => { + tracing::error!("save_profile(COMPANY) failed for user {}: {}", auth.user_id, e); + (StatusCode::INTERNAL_SERVER_ERROR, format!("Database error: {}", e)).into_response() + } }; }