tool per ticket automatici
This commit is contained in:
+45
-6
@@ -244,7 +244,7 @@ router.post('/', async (req, res) => {
|
||||
const {
|
||||
title, queue_id, state_id, priority_id, type_id,
|
||||
user_id, customer_id, customer_user_id, body, subject,
|
||||
responsible_user_id
|
||||
responsible_user_id, attachments
|
||||
} = req.body;
|
||||
|
||||
await client.query('BEGIN');
|
||||
@@ -328,11 +328,28 @@ router.post('/', async (req, res) => {
|
||||
]
|
||||
);
|
||||
|
||||
// Create initial article if body is provided
|
||||
if (body) {
|
||||
// Get sender type ID for "agent"
|
||||
// Create initial article if body or attachments are provided
|
||||
if (body || (attachments && attachments.length > 0)) {
|
||||
// Determine sender type (customer vs agent) and sender name/email
|
||||
let senderTypeName = 'agent';
|
||||
let customerFrom = 'OTRS Turbo Agent';
|
||||
|
||||
if (customer_user_id) {
|
||||
const custRes = await client.query(
|
||||
`SELECT email, first_name, last_name FROM customer_user WHERE login = $1`,
|
||||
[customer_user_id]
|
||||
);
|
||||
if (custRes.rows.length > 0) {
|
||||
const c = custRes.rows[0];
|
||||
customerFrom = `${c.first_name} ${c.last_name} <${c.email}>`;
|
||||
senderTypeName = 'customer';
|
||||
}
|
||||
}
|
||||
|
||||
// Get sender type ID
|
||||
const senderResult = await client.query(
|
||||
`SELECT id FROM article_sender_type WHERE name = 'agent'`
|
||||
`SELECT id FROM article_sender_type WHERE name = $1`,
|
||||
[senderTypeName]
|
||||
);
|
||||
const senderTypeId = senderResult.rows.length > 0 ? senderResult.rows[0].id : 1;
|
||||
|
||||
@@ -354,6 +371,7 @@ router.post('/', async (req, res) => {
|
||||
);
|
||||
|
||||
const articleId = articleResult.rows[0].id;
|
||||
const finalBody = body || 'File allegati in creazione';
|
||||
|
||||
await client.query(
|
||||
`INSERT INTO article_data_mime (
|
||||
@@ -365,8 +383,29 @@ router.post('/', async (req, res) => {
|
||||
'text/plain; charset=utf-8', EXTRACT(EPOCH FROM NOW())::INTEGER,
|
||||
NOW(), $5, NOW(), $5
|
||||
)`,
|
||||
[articleId, 'OTRS Turbo Agent', subject || title, body, operatorId]
|
||||
[articleId, customerFrom, subject || title, finalBody, operatorId]
|
||||
);
|
||||
|
||||
// Insert attachments if any
|
||||
if (attachments && Array.isArray(attachments)) {
|
||||
for (const att of attachments) {
|
||||
const contentBuffer = Buffer.from(att.content, 'base64');
|
||||
await client.query(
|
||||
`INSERT INTO article_data_mime_attachment (
|
||||
article_id, filename, content_size, content_type, disposition, content,
|
||||
create_time, create_by, change_time, change_by
|
||||
) VALUES ($1, $2, $3, $4, 'attachment', $5, NOW(), $6, NOW(), $6)`,
|
||||
[
|
||||
articleId,
|
||||
att.filename,
|
||||
contentBuffer.length,
|
||||
att.content_type || 'application/octet-stream',
|
||||
contentBuffer,
|
||||
operatorId
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
await client.query('COMMIT');
|
||||
|
||||
Reference in New Issue
Block a user