Ai-risk in Roadmap adds tasks/descriptions.
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

This commit is contained in:
Josh 2025-08-21 17:51:32 +00:00
parent b33b4ef6d1
commit 4c5fdea80c

View File

@ -522,6 +522,31 @@ async function applyOps(opsObj, req) {
return confirmations;
}
async function ensureDescriptionAndTasks({ socCode, jobDescription, tasks }) {
let desc = (jobDescription || '').trim();
let t = Array.isArray(tasks) ? tasks : (typeof tasks === 'string' ? [tasks] : []);
if (desc && t.length) return { jobDescription: desc, tasks: t };
try {
// hit server2 directly on the compose network
const r = await fetch(`http://server2:5001/api/onet/career-description/${encodeURIComponent(socCode)}`, {
headers: { Accept: 'application/json' }
});
if (r.ok) {
const j = await r.json();
if (!desc && j?.description) desc = String(j.description).trim();
if (!t.length && Array.isArray(j?.tasks)) t = j.tasks.map(x => String(x));
}
} catch (e) {
// best effort — keep whatever we had
console.warn('[ai-risk] enrich fetch failed:', e?.message || e);
}
return { jobDescription: desc, tasks: t };
}
/* ------------------------------------------------------------------
CAREER PROFILE ENDPOINTS
------------------------------------------------------------------ */
@ -2115,17 +2140,13 @@ app.post('/api/premium/milestone/convert-ai', authenticatePremiumUser, async (re
// server3.js
app.post('/api/premium/ai-risk-analysis', authenticatePremiumUser, async (req, res) => {
try {
const {
socCode,
careerName,
jobDescription,
tasks = []
} = req.body;
let { socCode, careerName, jobDescription, tasks = [] } = req.body;
if (!socCode) {
return res.status(400).json({ error: 'socCode is required.' });
}
({ jobDescription, tasks } = await ensureDescriptionAndTasks({ socCode, jobDescription, tasks }));
// 1) Check if we already have it
const cached = await getRiskAnalysisFromDB(socCode);
if (cached) {
@ -2196,17 +2217,14 @@ app.post('/api/premium/ai-risk-analysis', authenticatePremiumUser, async (req, r
app.post('/api/public/ai-risk-analysis', async (req, res) => {
try {
const {
socCode,
careerName,
jobDescription,
tasks = []
} = req.body;
let { socCode, careerName, jobDescription, tasks = [] } = req.body;
if (!socCode || !careerName) {
return res.status(400).json({ error: 'socCode and careerName are required.' });
}
({ jobDescription, tasks } = await ensureDescriptionAndTasks({ socCode, jobDescription, tasks }));
const prompt = `
The user has a career named: ${careerName}
Description: ${jobDescription}