Closure refactor
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
This commit is contained in:
parent
de3e14e739
commit
f3fe19360a
|
@ -3,13 +3,22 @@ const closure = require('./closure');
|
|||
|
||||
module.exports = async function(request, response, next) {
|
||||
try {
|
||||
const reqArgs = request.query;
|
||||
if (!reqArgs.to)
|
||||
throw new Error('The argument to is required');
|
||||
const reqArgs = request.body;
|
||||
|
||||
response.status(200).json({
|
||||
message: 'Success'
|
||||
});
|
||||
let toDate = new Date();
|
||||
toDate.setDate(toDate.getDate() - 1);
|
||||
|
||||
if (reqArgs.to) toDate = reqArgs.to;
|
||||
|
||||
const todayMinDate = new Date();
|
||||
minDate.setHours(0, 0, 0, 0);
|
||||
|
||||
const todayMaxDate = new Date();
|
||||
maxDate.setHours(23, 59, 59, 59);
|
||||
|
||||
// Prevent closure for current day
|
||||
if (toDate >= todayMinDate && toDate <= todayMaxDate)
|
||||
throw new Error('You cannot close tickets for today');
|
||||
|
||||
const tickets = await db.rawSql(`
|
||||
SELECT
|
||||
|
@ -36,7 +45,7 @@ module.exports = async function(request, response, next) {
|
|||
AND DATE(t.shipped) BETWEEN DATE_ADD(?, INTERVAL -2 DAY)
|
||||
AND util.dayEnd(?)
|
||||
AND t.refFk IS NULL
|
||||
GROUP BY t.id`, [reqArgs.to, reqArgs.to]);
|
||||
GROUP BY t.id`, [toDate, toDate]);
|
||||
|
||||
await closure.start(tickets, response.locals);
|
||||
|
||||
|
@ -52,7 +61,11 @@ module.exports = async function(request, response, next) {
|
|||
AND util.dayEnd(?)
|
||||
AND al.code NOT IN('DELIVERED','PACKED')
|
||||
AND t.routeFk
|
||||
AND z.name LIKE '%MADRID%'`, [reqArgs.to, reqArgs.to]);
|
||||
AND z.name LIKE '%MADRID%'`, [toDate, toDate]);
|
||||
|
||||
response.status(200).json({
|
||||
message: 'Success'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
|
|
@ -3,7 +3,7 @@ const closure = require('./closure');
|
|||
|
||||
module.exports = async function(request, response, next) {
|
||||
try {
|
||||
const reqArgs = request.query;
|
||||
const reqArgs = request.body;
|
||||
|
||||
if (!reqArgs.agencyModeId)
|
||||
throw new Error('The argument agencyModeId is required');
|
||||
|
@ -14,10 +14,6 @@ module.exports = async function(request, response, next) {
|
|||
if (!reqArgs.to)
|
||||
throw new Error('The argument to is required');
|
||||
|
||||
response.status(200).json({
|
||||
message: 'Success'
|
||||
});
|
||||
|
||||
const agencyIds = reqArgs.agencyModeId.split(',');
|
||||
const tickets = await db.rawSql(`
|
||||
SELECT
|
||||
|
@ -53,6 +49,10 @@ module.exports = async function(request, response, next) {
|
|||
]);
|
||||
|
||||
await closure.start(tickets, response.locals);
|
||||
|
||||
response.status(200).json({
|
||||
message: 'Success'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
|
|
@ -4,15 +4,11 @@ const closure = require('./closure');
|
|||
|
||||
module.exports = async function(request, response, next) {
|
||||
try {
|
||||
const reqArgs = request.query;
|
||||
const reqArgs = request.body;
|
||||
|
||||
if (!reqArgs.routeId)
|
||||
throw new Error('The argument routeId is required');
|
||||
|
||||
response.status(200).json({
|
||||
message: 'Success'
|
||||
});
|
||||
|
||||
const tickets = await db.rawSql(`
|
||||
SELECT
|
||||
t.id,
|
||||
|
@ -56,6 +52,10 @@ module.exports = async function(request, response, next) {
|
|||
const email = new Email('driver-route', args);
|
||||
await email.send();
|
||||
}
|
||||
|
||||
response.status(200).json({
|
||||
message: 'Success'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
|
|
@ -3,15 +3,11 @@ const closure = require('./closure');
|
|||
|
||||
module.exports = async function(request, response, next) {
|
||||
try {
|
||||
const reqArgs = request.query;
|
||||
const reqArgs = request.body;
|
||||
|
||||
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,
|
||||
|
@ -38,6 +34,10 @@ module.exports = async function(request, response, next) {
|
|||
GROUP BY e.ticketFk`, [reqArgs.ticketId]);
|
||||
|
||||
await closure.start(tickets, response.locals);
|
||||
|
||||
response.status(200).json({
|
||||
message: 'Success'
|
||||
});
|
||||
} catch (error) {
|
||||
next(error);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
const express = require('express');
|
||||
const router = new express.Router();
|
||||
|
||||
router.get('/all', require('./closeAll'));
|
||||
router.get('/by-ticket', require('./closeByTicket'));
|
||||
router.get('/by-agency', require('./closeByAgency'));
|
||||
router.get('/by-route', require('./closeByRoute'));
|
||||
router.post('/all', require('./closeAll'));
|
||||
router.post('/by-ticket', require('./closeByTicket'));
|
||||
router.post('/by-agency', require('./closeByAgency'));
|
||||
router.post('/by-route', require('./closeByRoute'));
|
||||
|
||||
module.exports = router;
|
||||
|
|
Loading…
Reference in New Issue