diff --git a/manager/components/ReportCard.tsx b/manager/components/ReportCard.tsx index 7e438fe..f0c2a28 100644 --- a/manager/components/ReportCard.tsx +++ b/manager/components/ReportCard.tsx @@ -132,7 +132,11 @@ const ReportCard: React.FC = ({ data, updateData }) => { const { submissions } = await res.json(); const subsMap: Record = {}; (submissions || []).forEach((s: any) => { - subsMap[s.prova_id] = { acertos: s.acertos, erros: s.erros }; + // Normalização agressiva para garantir o vínculo + const pId = String(s.prova_id || '').trim(); + if (pId) { + subsMap[pId] = { acertos: s.acertos, erros: s.erros }; + } }); setStudentSubmissions(subsMap); } @@ -148,11 +152,19 @@ const ReportCard: React.FC = ({ data, updateData }) => { if (linkedExams.length > 0) { linkedExams.forEach(exam => { - const existingGrade = dbNotas.find(g => String(g.disciplina_id).trim() === String(subject.id).trim() && String(g.periodo_id).trim() === String(period.id).trim() && String(g.prova_id).trim() === String(exam.id).trim()); + const existingGrade = dbNotas.find(g => + String(g.disciplina_id).trim() === String(subject.id).trim() && + (String(g.periodo_id).trim() === String(period.id).trim() || String(g.periodo_id).trim() === String(period.name).trim()) && + String(g.prova_id).trim() === String(exam.id).trim() + ); periodGrades[exam.id] = existingGrade ? Number(existingGrade.valor) : ''; }); } else { - const existingGrade = dbNotas.find(g => String(g.disciplina_id).trim() === String(subject.id).trim() && String(g.periodo_id).trim() === String(period.id).trim() && !g.prova_id); + const existingGrade = dbNotas.find(g => + String(g.disciplina_id).trim() === String(subject.id).trim() && + (String(g.periodo_id).trim() === String(period.id).trim() || String(g.periodo_id).trim() === String(period.name).trim()) && + !g.prova_id + ); periodGrades['direct'] = existingGrade ? Number(existingGrade.valor) : ''; } initialGrades[subject.id][period.id] = periodGrades; @@ -579,29 +591,31 @@ const ReportCard: React.FC = ({ data, updateData }) => { const maxScore = (exam as any).maxScore ?? 10; return (
-
-
-
- - {isActivity ? 'Atividade' : 'Prova'} - - {exam.title} -
-
- {exam.description && ( -

{exam.description}

- )} - {studentSubmissions[String(exam.id).trim()] && ( +
+
+ + {isActivity ? 'Atividade' : 'Prova'} + + {exam.title} +
+
+ {exam.description && ( +

{exam.description}

+ )} + {(() => { + const stats = studentSubmissions[String(exam.id).trim()]; + if (!stats) return null; + return (
- - {studentSubmissions[String(exam.id).trim()].acertos} Acertos + + {stats.acertos} Acertos - - {studentSubmissions[String(exam.id).trim()].erros} Erros + + {stats.erros} Erros
- )} -
+ ); + })()}
diff --git a/manager/scratch/list_all.js b/manager/scratch/list_all.js index 7c5f404..dee6080 100644 --- a/manager/scratch/list_all.js +++ b/manager/scratch/list_all.js @@ -1,17 +1,25 @@ -import pg from 'pg'; -const DATABASE_URL = 'postgresql://edumanager:EduManager2026!Seguro@127.0.0.1:5432/edumanager'; -const pool = new pg.Pool({ connectionString: DATABASE_URL }); -async function listAll() { +import pkg from 'pg'; +const { Pool } = pkg; + +const pool = new Pool({ + connectionString: 'postgresql://postgres:postgres@localhost:5432/edumanager' +}); + +async function check() { try { - const { rows: notas } = await pool.query('SELECT * FROM notas_boletim LIMIT 20'); - console.log('--- NOTAS NA TABELA ---'); - console.log(JSON.stringify(notas, null, 2)); - - const { rows: subs } = await pool.query('SELECT * FROM provas_submissoes LIMIT 10'); - console.log('--- SUBMISSÕES NA TABELA ---'); + console.log('--- SUBMISSÕES NO BANCO ---'); + const { rows: subs } = await pool.query('SELECT aluno_id, prova_id, acertos, erros FROM provas_submissoes'); console.log(JSON.stringify(subs, null, 2)); - } catch (err) { console.log('ERROR:' + err.message); } - finally { await pool.end(); } + + console.log('\n--- NOTAS NO BOLETIM ---'); + const { rows: notas } = await pool.query('SELECT aluno_id, disciplina_id, periodo_id, prova_id, valor FROM notas_boletim'); + console.log(JSON.stringify(notas, null, 2)); + } catch (err) { + console.error(err); + } finally { + await pool.end(); + } } -listAll(); + +check();