feat(agenda): GET /dentista-contato — resolve WhatsApp do dentista (Parte A)
Endpoint para a Secretária IA acionar o dentista responsável num encaixe sub-hora. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
@@ -344,6 +344,25 @@ export function createAgendaBridge(pool) {
|
|||||||
} catch (e) { res.status(500).json({ error: e.message }); }
|
} catch (e) { res.status(500).json({ error: e.message }); }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ── GET /dentista-contato ─────────────────────────────────────────────────────
|
||||||
|
// Resolve o WhatsApp de um dentista da clínica (Parte A: a IA aciona o Dr).
|
||||||
|
// Query: clinica_id (obrig.), nome? OU dentista_id?
|
||||||
|
router.get('/dentista-contato', async (req, res) => {
|
||||||
|
const clinicaId = String(req.query.clinica_id || '');
|
||||||
|
if (!clinicaId) return res.status(400).json({ error: 'clinica_id obrigatório' });
|
||||||
|
try {
|
||||||
|
const params = [clinicaId]; let where = 'clinica_id = $1';
|
||||||
|
if (req.query.dentista_id) { params.push(String(req.query.dentista_id)); where += ` AND id = $${params.length}`; }
|
||||||
|
else if (req.query.nome) { params.push(String(req.query.nome)); where += ` AND lower(nome) LIKE '%'||lower($${params.length})||'%'`; }
|
||||||
|
const { rows } = await pool.query(
|
||||||
|
`SELECT id, nome, telefone FROM dentistas WHERE ${where} AND ativo IS DISTINCT FROM 0 ORDER BY nome LIMIT 1`, params);
|
||||||
|
if (!rows.length) return res.json({ encontrado: false });
|
||||||
|
const d = rows[0];
|
||||||
|
const tel = String(d.telefone || '').replace(/\D/g, '');
|
||||||
|
res.json({ encontrado: true, dentista_id: d.id, nome: d.nome, telefone: tel || null });
|
||||||
|
} catch (e) { res.status(500).json({ error: e.message }); }
|
||||||
|
});
|
||||||
|
|
||||||
// ── POST /book ────────────────────────────────────────────────────────────────
|
// ── POST /book ────────────────────────────────────────────────────────────────
|
||||||
// Body: { clinica_id, dentista_id, start, end?, paciente_nome, paciente_celular, procedimento? }
|
// Body: { clinica_id, dentista_id, start, end?, paciente_nome, paciente_celular, procedimento? }
|
||||||
router.post('/book', async (req, res) => {
|
router.post('/book', async (req, res) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user