From 62769c9b7e73920257745d624e16987fb96f06f6 Mon Sep 17 00:00:00 2001 From: Celes Renata Date: Fri, 17 Apr 2026 05:26:08 +0000 Subject: [PATCH] fix: macro impacts API returns {exposure_profile, impacts} to match frontend type API was returning a flat array but frontend expects CompanyMacroImpacts wrapper with exposure_profile and impacts fields. Also queries the exposure_profiles table for the company's active profile. --- services/api/app.py | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/services/api/app.py b/services/api/app.py index c4275ea..947ba22 100644 --- a/services/api/app.py +++ b/services/api/app.py @@ -2289,12 +2289,37 @@ async def get_macro_impacts_for_ticker( limit: int = Query(default=50, le=200), offset: int = 0, ): - """Macro impacts for a specific company. + """Macro impacts and exposure profile for a specific company. + + Returns { exposure_profile, impacts } matching the frontend + CompanyMacroImpacts type. Requirements: 8.2 """ + ticker_upper = ticker.upper() + + # Fetch exposure profile for this company + profile_row = await pool.fetchrow( + """SELECT ep.id, ep.company_id, ep.geographic_revenue_mix, + ep.supply_chain_regions, ep.key_input_commodities, + ep.regulatory_jurisdictions, ep.market_position_tier, + ep.export_dependency_pct, ep.source, ep.confidence, + ep.version, ep.active, ep.created_at, ep.updated_at + FROM exposure_profiles ep + JOIN companies c ON c.id = ep.company_id + WHERE c.ticker = $1 AND ep.active = TRUE + ORDER BY ep.version DESC LIMIT 1""", + ticker_upper, + ) + exposure_profile = _row_to_dict(profile_row) if profile_row else None + if exposure_profile: + exposure_profile["geographic_revenue_mix"] = _parse_jsonb( + exposure_profile.get("geographic_revenue_mix") + ) + + # Fetch macro impact records conditions = ["mir.ticker = $1"] - params: list[Any] = [ticker.upper()] + params: list[Any] = [ticker_upper] idx = 2 if since: @@ -2317,12 +2342,16 @@ async def get_macro_impacts_for_ticker( LIMIT ${idx} OFFSET ${idx + 1}""", *params, limit, offset, ) - results = [] + impacts = [] for r in rows: d = _row_to_dict(r) d["contributing_factors"] = _parse_jsonb(d.get("contributing_factors")) - results.append(d) - return results + impacts.append(d) + + return { + "exposure_profile": exposure_profile, + "impacts": impacts, + } # ---------------------------------------------------------------------------