From 435176c0c37aa9bffc0658b564c02c2e3b28398b Mon Sep 17 00:00:00 2001 From: VPS 4 Builder Date: Thu, 14 May 2026 04:26:03 +0200 Subject: [PATCH] fix(backend): add camelCase response mapping for all GET endpoints PG stores columns lowercase but frontend expects camelCase. Each GET endpoint now maps the response to include camelCase aliases alongside the lowercase fields. - agendamentos: dentistaId, pacienteNome, pacienteCelular - dentistas: corAgenda - procedimentos: especialidadeId, especialidadeNome, valorParticular, codigoInterno; fix valoresPlanos filter (v.procedimentoid) and map planoId, planoNome, codigoPlano - guias: full camelCase map (dataSolicitacao, beneficiarioNome, tipoTratamento, etc.) - gto-builder: map items (builderId, procedimentoId, codigoTUSS, valorTotal, etc.) and builder fields (pacienteId, dentistaId, credenciadaId) Co-Authored-By: Claude Sonnet 4.6 --- backend/server.js | 59 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 52 insertions(+), 7 deletions(-) diff --git a/backend/server.js b/backend/server.js index 57e1e12..b11a768 100644 --- a/backend/server.js +++ b/backend/server.js @@ -529,7 +529,7 @@ app.get('/api/dentistas', async (req, res) => { } query += ' ORDER BY ordem ASC, nome ASC'; const { rows } = await pool.query(query, params); - res.json(rows.map(d => ({ ...d, ativo: !!d.ativo }))); + res.json(rows.map(d => ({ ...d, ativo: !!d.ativo, corAgenda: d.coragenda }))); } catch (err) { res.status(500).json({ error: err.message }); } }); @@ -666,7 +666,14 @@ app.get('/api/reports/productivity', async (req, res) => { app.get('/api/agendamentos', async (req, res) => { try { const { rows } = await pool.query('SELECT * FROM agendamentos'); - res.json(rows.map(r => ({ ...r, start: r.start_time, end: r.end_time }))); + res.json(rows.map(r => ({ + ...r, + dentistaId: r.dentistaid, + pacienteNome: r.pacientenome, + pacienteCelular: r.pacientecelular, + start: r.start_time, + end: r.end_time + }))); } catch (err) { res.status(500).json({ error: err.message }); } }); @@ -848,10 +855,19 @@ app.get('/api/procedimentos', async (req, res) => { const data = procs.map(p => ({ ...p, - valorParticular: parseFloat(p.valorParticular || 0), + especialidadeId: p.especialidadeid, + especialidadeNome: p.especialidadenome, + valorParticular: parseFloat(p.valorparticular || 0), + codigoInterno: p.codigointerno, valoresPlanos: valores - .filter(v => v.procedimentoId === p.id) - .map(v => ({ ...v, valor: parseFloat(v.valor || 0) })) + .filter(v => v.procedimentoid === p.id) + .map(v => ({ + ...v, + planoId: v.planoid, + planoNome: v.planonome, + codigoPlano: v.codigoplano, + valor: parseFloat(v.valor || 0) + })) })); res.json(data); } catch (err) { res.status(500).json({ error: err.message }); } @@ -1057,8 +1073,20 @@ app.get('/api/guias', async (req, res) => { const { rows } = await pool.query(query, [...params, limit, offset]); const { rows: totalRows } = await pool.query(countQuery, params); + const mapGuia = (g) => ({ + ...g, + numeroGuiaPrestador: g.numeroguiaprestador, + numeroGuiaOperadora: g.numeroguiaoperadora, + dataSolicitacao: g.datasolicitacao, + tipoTratamento: g.tipotratamento, + beneficiarioId: g.beneficiarioid, + beneficiarioNome: g.beneficiarionome, + beneficiarioIdentificacao: g.beneficiarioidentificacao, + createdAt: g.createdat + }); + res.json({ - data: rows, + data: rows.map(mapGuia), total: totalRows[0].total, page: parseInt(page), pageSize: limit @@ -1085,7 +1113,24 @@ app.get('/api/gto-builder/:id', async (req, res) => { try { const { rows: builder } = await pool.query('SELECT * FROM gto_builders WHERE id = $1', [req.params.id]); const { rows: items } = await pool.query('SELECT * FROM gto_items WHERE builderid = $1', [req.params.id]); - res.json({ ...builder[0], items }); + const mappedItems = items.map(i => ({ + ...i, + builderId: i.builderid, + procedimentoId: i.procedimentoid, + codigoTUSS: i.codigotuss, + codigoInterno: i.codigointerno, + valorUnitario: parseFloat(i.valorunitario || 0), + valorTotal: parseFloat(i.valortotal || 0), + anexosCount: i.anexoscount + })); + const b = builder[0]; + res.json({ + ...b, + pacienteId: b?.pacienteid, + dentistaId: b?.dentistaid, + credenciadaId: b?.credenciadaid, + items: mappedItems + }); } catch (err) { res.status(500).json({ error: err.message }); } });