fix: note temporanee che non funzionavano. feat: le note possono essere inviate ad otrs senza numero di ticket. style: rivisti alcuni nomi e colore per invio di una nota temporanea in otrs.

This commit is contained in:
Gabriele Cimaschi committed 2026-09-07 17:58:13 +02:00
1 parent b828d60bb2
commit f21be0abcb
9 files changed
+216 -70

No files matched your search

+8 -7
View File
@@ -482,7 +482,7 @@ router.post('/', async (req, res) => {
// Generate ticket number: get next counter value for today (daily reset)
const now = new Date();
const systemId = process.env.OTRS_SYSTEM_ID || '10';
const systemId = process.env.OTRS_SYSTEM_ID || String(operatorId);
const datePrefix = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}${systemId}`;
// 1. Fetch current maximum counter in ticket table for today
@@ -748,8 +748,9 @@ router.patch('/:id', async (req, res) => {
const updates = req.body; // { ticket_state_id, ticket_priority_id, queue_id, user_id, type_id, title, note }
const operatorId = parseInt(req.headers['x-agent-id'], 10) || 1;
const timeUnit = parseFloat(updates.time_unit);
const noteSubjectText = typeof updates.note_subject === 'string' ? updates.note_subject.trim() : '';
const noteText = typeof updates.note === 'string' ? updates.note.trim() : (typeof updates.note_text === 'string' ? updates.note_text.trim() : '');
const hasNote = noteText.length > 0;
const hasNote = noteText.length > 0 || noteSubjectText.length > 0;
// Fetch current ticket first (needed for both REST dummy fields and database fallback)
let current;
@@ -810,8 +811,8 @@ router.patch('/:id', async (req, res) => {
Ticket: ticketFields
};
if (hasNote || (!isNaN(timeUnit) && timeUnit > 0)) {
const noteSubject = hasNote ? noteText : 'Consuntivazione';
const noteBody = hasNote ? noteText : 'Consuntivazione';
const noteSubject = noteSubjectText || (hasNote ? noteText : 'Consuntivazione');
const noteBody = noteText || noteSubjectText || 'Consuntivazione';
const articleObj = {
CommunicationChannel: 'Internal',
SenderType: 'agent',
@@ -993,8 +994,8 @@ router.patch('/:id', async (req, res) => {
const articleId = articleResult.rows[0].id;
const now = new Date();
const contentPath = `${now.getFullYear()}/${String(now.getMonth() + 1).padStart(2, '0')}/${String(now.getDate()).padStart(2, '0')}`;
const noteSubject = hasNote ? noteText : 'Consuntivazione';
const noteBodyRaw = hasNote ? noteText : 'Consuntivazione';
const noteSubject = noteSubjectText || (hasNote ? noteText : 'Consuntivazione');
const noteBodyRaw = noteText || noteSubjectText || 'Consuntivazione';
const safeBody = noteBodyRaw.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\n/g, '<br/>');
const htmlBody = `<!DOCTYPE html><html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/></head><body style="font-family:Geneva,Helvetica,Arial,sans-serif; font-size: 12px;">${safeBody}</body></html>`;
const binaryBody = Buffer.from(htmlBody, 'utf-8');
@@ -2210,7 +2211,7 @@ router.post('/auto-time', async (req, res) => {
// Generate ticket number (daily reset)
const now = new Date();
const systemId = process.env.OTRS_SYSTEM_ID || '10';
const systemId = process.env.OTRS_SYSTEM_ID || String(operatorId);
const datePrefix = `${now.getFullYear()}${String(now.getMonth() + 1).padStart(2, '0')}${String(now.getDate()).padStart(2, '0')}${systemId}`;
const maxTicketResult = await client.query(