fix: remove TO_CHAR timezone stripping from portal frequency API - return ISO dates with timezone via pg driver toISOString to match Manager JSON format
This commit is contained in:
parent
8b05fd95f0
commit
5c49093ed0
|
|
@ -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' });
|
||||
|
|
|
|||
Loading…
Reference in New Issue