feat(api): implementar endpoints M2M /api/external/tickets para sigma-robot y worker de integracion

This commit is contained in:
2026-10-27 11:56:45 -05:00
parent 5c7a8c925b
commit 10a614ed47
5 changed files with 664 additions and 7 deletions
+23 -3
View File
@@ -48,13 +48,33 @@ const Ticket = {
`, [id]);
return rows[0];
},
create: async (companyId, userId, departmentId, asunto, mensaje, prioridad = 'media') => {
create: async (companyId, userId, departmentId, asunto, mensaje, prioridad = 'media', extra = {}) => {
const {
origen = 'web',
origen_externo_id = null,
app_origen = null,
solicitante_nombre = null,
solicitante_email = null,
solicitante_telefono = null,
tipo = 'consulta'
} = extra;
const [result] = await db.query(
'INSERT INTO tickets (company_id, user_id, department_id, asunto, mensaje, prioridad) VALUES (?, ?, ?, ?, ?, ?)',
[companyId, userId, departmentId, asunto, mensaje, prioridad]
`INSERT INTO tickets
(company_id, user_id, department_id, asunto, mensaje, prioridad, origen, origen_externo_id, app_origen, solicitante_nombre, solicitante_email, solicitante_telefono, tipo)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
[companyId, userId, departmentId, asunto, mensaje, prioridad, origen, origen_externo_id, app_origen, solicitante_nombre, solicitante_email, solicitante_telefono, tipo]
);
return result.insertId;
},
findByOrigenExterno: async (companyId, origen, origenExternoId) => {
if (!origenExternoId) return null;
const [rows] = await db.query(
'SELECT * FROM tickets WHERE company_id = ? AND origen = ? AND origen_externo_id = ?',
[companyId, origen, String(origenExternoId)]
);
return rows[0] || null;
},
update: async (id, data) => {
const fields = [];
const values = [];