Aggiunte stored procedure più utili le altre pfff
This commit is contained in:
+53
-1
@@ -38,7 +38,8 @@ router.get('/', async (req, res) => {
|
||||
const {
|
||||
queue_id, state_id, priority_id, user_id, type_id,
|
||||
search, sort_by = 'create_time', sort_dir = 'DESC',
|
||||
page = 1, per_page = 50
|
||||
page = 1, per_page = 50,
|
||||
date_from, date_to
|
||||
} = req.query;
|
||||
|
||||
const conditions = [];
|
||||
@@ -65,6 +66,14 @@ router.get('/', async (req, res) => {
|
||||
conditions.push(`t.type_id = $${paramIdx++}`);
|
||||
params.push(parseInt(type_id));
|
||||
}
|
||||
if (date_from) {
|
||||
conditions.push(`t.create_time >= $${paramIdx++}`);
|
||||
params.push(new Date(date_from));
|
||||
}
|
||||
if (date_to) {
|
||||
conditions.push(`t.create_time <= $${paramIdx++}`);
|
||||
params.push(new Date(date_to));
|
||||
}
|
||||
if (search) {
|
||||
conditions.push(`(t.title ILIKE $${paramIdx} OR t.tn ILIKE $${paramIdx})`);
|
||||
params.push(`%${search}%`);
|
||||
@@ -865,4 +874,47 @@ router.patch('/batch/update', async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/tickets/:id/retrodata-ticket — Retrodate ticket creation time
|
||||
router.post('/:id/retrodata-ticket', async (req, res) => {
|
||||
try {
|
||||
const { id } = req.params;
|
||||
const { create_time } = req.body;
|
||||
if (!create_time) {
|
||||
return res.status(400).json({ error: 'Specificare la data di creazione.' });
|
||||
}
|
||||
|
||||
// Fetch TN for the ticket
|
||||
const tnResult = await pool.query('SELECT tn FROM ticket WHERE id = $1', [id]);
|
||||
if (tnResult.rows.length === 0) {
|
||||
return res.status(404).json({ error: 'Ticket non trovato.' });
|
||||
}
|
||||
const tn = tnResult.rows[0].tn;
|
||||
|
||||
// Execute stored procedure
|
||||
await pool.query('CALL prretrodataticket($1, $2)', [tn, new Date(create_time)]);
|
||||
res.json({ message: 'Ticket retrodatato correttamente.' });
|
||||
} catch (err) {
|
||||
console.error('Errore in prretrodataticket:', err);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// POST /api/tickets/articles/:articleId/retrodata-article — Retrodate article creation time
|
||||
router.post('/articles/:articleId/retrodata-article', async (req, res) => {
|
||||
try {
|
||||
const { articleId } = req.params;
|
||||
const { create_time } = req.body;
|
||||
if (!create_time) {
|
||||
return res.status(400).json({ error: 'Specificare la data di creazione.' });
|
||||
}
|
||||
|
||||
// Execute stored procedure
|
||||
await pool.query('CALL prretrodataarticolo($1, $2)', [parseInt(articleId), new Date(create_time)]);
|
||||
res.json({ message: 'Articolo retrodatato correttamente.' });
|
||||
} catch (err) {
|
||||
console.error('Errore in prretrodataarticolo:', err);
|
||||
res.status(500).json({ error: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
module.exports = router;
|
||||
|
||||
Reference in New Issue
Block a user