aggiunta gestione html/testo e allegati
This commit is contained in:
+37
-2
@@ -210,13 +210,24 @@ router.get('/:id', async (req, res) => {
|
||||
LEFT JOIN users creator ON a.create_by = creator.id
|
||||
LEFT JOIN time_accounting ta ON a.id = ta.article_id
|
||||
WHERE a.ticket_id = $1
|
||||
ORDER BY a.create_time ASC`,
|
||||
ORDER BY a.create_time DESC, a.id DESC`,
|
||||
[id]
|
||||
);
|
||||
|
||||
// Fetch attachments metadata for all articles in the ticket
|
||||
const attachmentsResult = await pool.query(
|
||||
`SELECT id, article_id, filename, content_size, content_type, disposition
|
||||
FROM article_data_mime_attachment
|
||||
WHERE article_id IN (
|
||||
SELECT id FROM article WHERE ticket_id = $1
|
||||
)`,
|
||||
[id]
|
||||
);
|
||||
|
||||
res.json({
|
||||
ticket: ticketResult.rows[0],
|
||||
articles: articlesResult.rows,
|
||||
attachments: attachmentsResult.rows,
|
||||
});
|
||||
} catch (err) {
|
||||
console.error('Error fetching ticket detail:', err);
|
||||
@@ -578,7 +589,7 @@ router.get('/:id/articles', async (req, res) => {
|
||||
LEFT JOIN users creator ON a.create_by = creator.id
|
||||
LEFT JOIN time_accounting ta ON a.id = ta.article_id
|
||||
WHERE a.ticket_id = $1
|
||||
ORDER BY a.create_time ASC`,
|
||||
ORDER BY a.create_time DESC, a.id DESC`,
|
||||
[id]
|
||||
);
|
||||
res.json(result.rows);
|
||||
@@ -917,4 +928,28 @@ router.post('/articles/:articleId/retrodata-article', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// GET /api/tickets/attachments/:id — Download/View attachment
|
||||
router.get('/attachments/:id', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const result = await pool.query(
|
||||
`SELECT filename, content_type, content
|
||||
FROM article_data_mime_attachment
|
||||
WHERE id = $1`,
|
||||
[id]
|
||||
);
|
||||
if (result.rows.length === 0) {
|
||||
return res.status(404).send('Allegato non trovato.');
|
||||
}
|
||||
const attachment = result.rows[0];
|
||||
|
||||
res.setHeader('Content-Type', attachment.content_type || 'application/octet-stream');
|
||||
res.setHeader('Content-Disposition', `attachment; filename="${attachment.filename}"`);
|
||||
res.send(attachment.content);
|
||||
} catch (err) {
|
||||
console.error('Errore download allegato:', err);
|
||||
res.status(500).send(err.message);
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user