diff --git a/portal/server.selfhosted.js b/portal/server.selfhosted.js index 9597675..a1c3a6e 100644 --- a/portal/server.selfhosted.js +++ b/portal/server.selfhosted.js @@ -294,10 +294,18 @@ app.get('/api/portal/notas', authMiddleware, async (req, res) => { app.get('/api/portal/frequencia', authMiddleware, async (req, res) => { try { const { rows: dbAttendance } = await pool.query( - 'SELECT id, aluno_id as "studentId", turma_id as "classId", TO_CHAR(data, \'YYYY-MM-DD"T"HH24:MI:SS\') as "date", foto as "photo", verificado as "verified", tipo as "type", justificativa as "justification", justificativa_aceita as "justificationAccepted" FROM frequencias WHERE aluno_id = $1', + 'SELECT id, aluno_id as "studentId", turma_id as "classId", data as "rawDate", foto as "photo", verificado as "verified", tipo as "type", justificativa as "justification", justificativa_aceita as "justificationAccepted" FROM frequencias WHERE aluno_id = $1', [req.user.studentId] ); - res.json({ attendance: dbAttendance }); + // Converter datas para ISO string COM timezone (formato idêntico ao Manager JSON) + // O pg driver retorna TIMESTAMPTZ como Date objects do JS, e toISOString() preserva o UTC correto. + // O browser então faz new Date(isoString) e converte para hora local automaticamente. + const attendance = dbAttendance.map(row => ({ + ...row, + date: row.rawDate instanceof Date ? row.rawDate.toISOString() : (row.rawDate || ''), + rawDate: undefined + })); + res.json({ attendance }); } catch (err) { console.error('Frequencia error:', err); res.status(500).json({ error: 'Erro interno' });