32 lines
919 B
JavaScript
32 lines
919 B
JavaScript
const db = require('vn-print/core/database');
|
|
const closure = require('./closure');
|
|
|
|
module.exports = async function(request, response, next) {
|
|
try {
|
|
const reqArgs = request.query;
|
|
|
|
if (!reqArgs.ticketId)
|
|
throw new Error('The argument ticketId is required');
|
|
|
|
response.status(200).json({
|
|
message: 'Success'
|
|
});
|
|
|
|
const tickets = await db.rawSql(`
|
|
SELECT
|
|
t.id
|
|
FROM expedition e
|
|
JOIN ticket t ON t.id = e.ticketFk
|
|
JOIN ticketState ts ON ts.ticketFk = t.id
|
|
JOIN alertLevel al ON al.id = ts.alertLevel
|
|
WHERE al.code = 'PACKED'
|
|
AND t.id = ?
|
|
AND t.refFk IS NULL
|
|
GROUP BY e.ticketFk`, [reqArgs.ticketId]);
|
|
|
|
await closure.start(tickets, response.locals);
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|