From c16d029432f4a21b287768bdd4f33ac50213fa46 Mon Sep 17 00:00:00 2001 From: Josh Date: Sun, 10 Aug 2025 14:21:24 +0000 Subject: [PATCH] fixed salary call after security enhancements --- .env | 2 +- backend/server2.js | 20 +++++------ src/components/CareerRoadmap.js | 59 ++++++++++++++++++--------------- 3 files changed, 43 insertions(+), 38 deletions(-) diff --git a/.env b/.env index c913fe6..2d66382 100644 --- a/.env +++ b/.env @@ -2,7 +2,7 @@ CORS_ALLOWED_ORIGINS=https://dev1.aptivaai.com,http://34.16.120.118:3000,http:// SERVER1_PORT=5000 SERVER2_PORT=5001 SERVER3_PORT=5002 -IMG_TAG=9365ce4-202508091934 +IMG_TAG=4cfdf84-202508101351 ENV_NAME=dev PROJECT=aptivaai-dev \ No newline at end of file diff --git a/backend/server2.js b/backend/server2.js index 4d3d597..a4bb11d 100755 --- a/backend/server2.js +++ b/backend/server2.js @@ -57,12 +57,12 @@ const chatLimiter = rateLimit({ const institutionData = JSON.parse(fs.readFileSync(INSTITUTION_DATA_PATH, 'utf8')); // ── DEK + canary bootstrap (use raw pool to avoid DAO interception) ── -const db = pool.raw || pool; +const sql = pool.raw || pool; try { await initEncryption(); - await db.query('SELECT 1'); - await verifyCanary(db); + await sql.query('SELECT 1'); + await verifyCanary(sql); } catch (e) { console.error('FATAL during crypto/DB bootstrap:', e?.message || e); process.exit(1); @@ -84,7 +84,7 @@ app.get('/livez', (_req, res) => res.type('text').send('OK')); app.get('/readyz', async (_req, res) => { try { await initEncryption(); - await verifyCanary(db); // <-- use raw pool + await verifyCanary(sql); // <-- use raw pool return res.type('text').send('OK'); } catch (e) { console.error('[READYZ]', e.message); @@ -122,7 +122,7 @@ app.get('/healthz', async (_req, res) => { // DB ping const t0 = Date.now(); try { - await db.query('SELECT 1'); // <-- use raw pool + await sql.query('SELECT 1'); // <-- use raw pool out.checks.db.ok = true; out.checks.db.ping_ms = Date.now() - t0; } catch (e) { @@ -131,7 +131,7 @@ app.get('/healthz', async (_req, res) => { // canary try { - await verifyCanary(db); // <-- use raw pool + await verifyCanary(sql); // <-- use raw pool out.checks.canary.ok = true; } catch (e) { out.checks.canary.error = e.message; @@ -877,10 +877,10 @@ app.get('/api/salary', async (req, res) => { let regionalRow = null; let nationalRow = null; - if (area) { - regionalRow = await db.get(regionalQuery, [socCode, area]); + if (area) { + regionalRow = await dbSqlite.get(regionalQuery, [socCode, area]); } - nationalRow = await db.get(nationalQuery, [socCode]); + nationalRow = await dbSqlite.get(nationalQuery, [socCode]); if (!regionalRow && !nationalRow) { console.log('No salary data found for:', { socCode, area }); @@ -926,7 +926,7 @@ app.post('/api/job-zones', async (req, res) => { FROM salary_data WHERE OCC_CODE IN (${placeholders}) `; - const rows = await db.all(q, formattedSocCodes); + const rows = await dbSqlite.all(q, formattedSocCodes); console.log('Salary Data Query Results:', rows); const jobZoneMapping = rows.reduce((acc, row) => { diff --git a/src/components/CareerRoadmap.js b/src/components/CareerRoadmap.js index 49a7253..fcd496f 100644 --- a/src/components/CareerRoadmap.js +++ b/src/components/CareerRoadmap.js @@ -388,14 +388,15 @@ export default function CareerRoadmap({ selectedCareer: initialCareer }) { const [buttonDisabled, setButtonDisabled] = useState(false); const [aiRisk, setAiRisk] = useState(null); - const { setChatSnapshot } = useContext(ChatCtx); + const chat = useContext(ChatCtx) || {}; + const setChatSnapshot = chat?.setChatSnapshot; const reloadScenarioAndCollege = useCallback(async () => { if (!careerProfileId) return; const s = await authFetch( - `api/premium/career-profile/${careerProfileId}` + `/api/premium/career-profile/${careerProfileId}` ); if (s.ok) { const row = await s.json(); @@ -405,7 +406,7 @@ export default function CareerRoadmap({ selectedCareer: initialCareer }) { } const c = await authFetch( - `api/premium/college-profile?careerProfileId=${careerProfileId}` + `/api/premium/college-profile?careerProfileId=${careerProfileId}` ); if (c.ok) setCollegeProfile(await c.json()); }, [careerProfileId]); @@ -659,7 +660,11 @@ const uiSnap = useMemo(() => ({ ]); /* push the snapshot to the chat context */ -useEffect(() => setChatSnapshot(uiSnap), [uiSnap, setChatSnapshot]); +useEffect(() => { + if (typeof setChatSnapshot === 'function') { + setChatSnapshot(uiSnap); + } + }, [uiSnap, setChatSnapshot]); useEffect(() => { @@ -828,7 +833,7 @@ async function fetchAiRisk(socCode, careerName, description, tasks) { try { // 1) Check server2 for existing entry - const localRiskRes = await axios.get(`api/ai-risk/${socCode}`); + const localRiskRes = await axios.get(`/api/ai-risk/${socCode}`); aiRisk = localRiskRes.data; // { socCode, riskLevel, ... } } catch (err) { // 2) If 404 => call server3 @@ -906,7 +911,7 @@ useEffect(() => { (async () => { try { const qs = new URLSearchParams({ socCode: strippedSocCode, area: userArea }); - const res = await fetch(`api/salary?${qs}`, { signal: ctrl.signal }); + const res = await fetch(`/api/salary?${qs}`, { signal: ctrl.signal }); if (res.ok) { setSalaryData(await res.json()); @@ -938,7 +943,7 @@ useEffect(() => { try { const qs = new URLSearchParams({ state: userState }); const res = await authFetch( - `api/projections/${strippedSocCode}?${qs}`, + `/api/projections/${strippedSocCode}?${qs}`, { signal: ctrl.signal } ); @@ -965,7 +970,7 @@ useEffect(() => { // fetch impacts const imPromises = allMilestones.map((m) => - authFetch(`api/premium/milestone-impacts?milestone_id=${m.id}`) + authFetch(`/api/premium/milestone-impacts?milestone_id=${m.id}`) .then((r) => (r.ok ? r.json() : null)) .then((dd) => dd?.impacts || []) .catch((e) => { @@ -1285,8 +1290,8 @@ const fetchMilestones = useCallback(async () => { if (!careerProfileId) return; const [profRes, uniRes] = await Promise.all([ - authFetch(`api/premium/milestones?careerProfileId=${careerProfileId}`), - authFetch(`api/premium/milestones?careerProfileId=universal`) + authFetch(`/api/premium/milestones?careerProfileId=${careerProfileId}`), + authFetch(`/api/premium/milestones?careerProfileId=universal`) ]); if (!profRes.ok || !uniRes.ok) return; @@ -1312,23 +1317,23 @@ const handleMilestonesCreated = useCallback( return (
- {/* 0) New CareerCoach at the top */} - { - // store it in local state - setAiRisk(riskData); - }} - /> + + {careerProfileId ? ( + { setAiRisk(riskData); }} + /> + ) : ( +
+ Loading your roadmap… +
+ )} {/* 1) Then your "Where Am I Now?" */}

Where you are now and where you are going: