Actualizar server.js
This commit is contained in:
30
server.js
30
server.js
@@ -976,6 +976,36 @@ app.put("/clients/:id", authMiddleware, async (req, res) => {
|
|||||||
} catch (e) { res.status(500).json({ ok: false }); }
|
} catch (e) { res.status(500).json({ ok: false }); }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// ==========================================
|
||||||
|
// 📝 RUTAS DE PLANTILLAS DE MENSAJES
|
||||||
|
// ==========================================
|
||||||
|
app.get("/templates", authMiddleware, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const q = await pool.query("SELECT type, content FROM message_templates WHERE owner_id=$1", [req.user.accountId]);
|
||||||
|
res.json({ ok: true, templates: q.rows });
|
||||||
|
} catch (e) {
|
||||||
|
res.status(500).json({ ok: false, error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
app.post("/templates", authMiddleware, async (req, res) => {
|
||||||
|
try {
|
||||||
|
const { type, content } = req.body;
|
||||||
|
if (!type) return res.status(400).json({ ok: false, error: "Falta el tipo de plantilla" });
|
||||||
|
|
||||||
|
await pool.query(`
|
||||||
|
INSERT INTO message_templates (owner_id, type, content)
|
||||||
|
VALUES ($1, $2, $3)
|
||||||
|
ON CONFLICT (owner_id, type) DO UPDATE SET content = EXCLUDED.content
|
||||||
|
`, [req.user.accountId, type, content || ""]);
|
||||||
|
|
||||||
|
res.json({ ok: true });
|
||||||
|
} catch (e) {
|
||||||
|
console.error("Error guardando plantilla:", e);
|
||||||
|
res.status(500).json({ ok: false, error: e.message });
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// ==========================================
|
// ==========================================
|
||||||
// 🎨 RUTAS DE ESTADOS DEL SISTEMA (SAAS COMPLETO)
|
// 🎨 RUTAS DE ESTADOS DEL SISTEMA (SAAS COMPLETO)
|
||||||
// ==========================================
|
// ==========================================
|
||||||
|
|||||||
Reference in New Issue
Block a user