From efe9cad56459abacb9be1f6e12e704fbf1587e88 Mon Sep 17 00:00:00 2001 From: achieven Date: Fri, 13 Apr 2018 14:51:10 +0300 Subject: [PATCH 1/3] fixed syntax error --- routes/api/api_gate_routes.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/routes/api/api_gate_routes.js b/routes/api/api_gate_routes.js index ad80c4b72..116d6e429 100644 --- a/routes/api/api_gate_routes.js +++ b/routes/api/api_gate_routes.js @@ -10,7 +10,8 @@ var Event = require('../../models/event').Event; var UsersGroup = require('../../models/user').UsersGroup; var UsersGroupMembership = require('../../models/user').UsersGroupMembership; -// const constants = require('../../models/constants'); +const constants = require('../../models/constants'); +// const volunteersAPI = require('../../libs/volunteers')(); const ERRORS = { GATE_CODE_MISSING: 'gate_code is missing or incorrect', @@ -246,8 +247,8 @@ router.post('/tickets-counter', async function (req, res) { router.post( '/vehicle-action/:direction', - async function (req, res) { - if (!constants..includes(req.params.direction)) { + async function (req, res) { + if (!constants.includes(req.params.direction)) { return sendError(res, 500, "INVALID_VEHICLE_DIRECTION"); } try { @@ -259,8 +260,8 @@ router.post( } catch (errorObj) { return sendError(res, 500, errorObj); } - } -}); + } +); router.get( '/vehicle-counter', @@ -278,7 +279,7 @@ router.get( ); router.get( - 'all-vehicle-actions/:dateFrom/:dateTo', + '/all-vehicle-actions/:dateFrom/:dateTo', async function (req, res) { try { let vehicleTimestamps = await knex('vehicle_entries').where('timestamp', '>', req.params.dateFrom).where('timestamp', '<', req.params.dateTo); From 1c0b09a2655506ba267bab91c788846300540c19 Mon Sep 17 00:00:00 2001 From: achieven Date: Fri, 13 Apr 2018 15:00:58 +0300 Subject: [PATCH 2/3] fixed syntax error --- routes/api/api_gate_routes.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/api/api_gate_routes.js b/routes/api/api_gate_routes.js index 116d6e429..de9bd5469 100644 --- a/routes/api/api_gate_routes.js +++ b/routes/api/api_gate_routes.js @@ -248,7 +248,7 @@ router.post('/tickets-counter', async function (req, res) { router.post( '/vehicle-action/:direction', async function (req, res) { - if (!constants.includes(req.params.direction)) { + if (!constants.VEHICLE_ENTRY_DIRECTION.includes(req.params.direction)) { return sendError(res, 500, "INVALID_VEHICLE_DIRECTION"); } try { From 08b9c9b31ed38fb396d12db22ad693730bdc611c Mon Sep 17 00:00:00 2001 From: achieven Date: Fri, 13 Apr 2018 16:52:37 +0300 Subject: [PATCH 3/3] finished api, code not perfect --- routes/api/api_gate_routes.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/routes/api/api_gate_routes.js b/routes/api/api_gate_routes.js index de9bd5469..84461eb3e 100644 --- a/routes/api/api_gate_routes.js +++ b/routes/api/api_gate_routes.js @@ -246,14 +246,14 @@ router.post('/tickets-counter', async function (req, res) { }); router.post( - '/vehicle-action/:direction', + '/vehicle-action/:event_id/:direction', async function (req, res) { if (!constants.VEHICLE_ENTRY_DIRECTION.includes(req.params.direction)) { return sendError(res, 500, "INVALID_VEHICLE_DIRECTION"); } try { - let direction = 'arrival' === req.params.direction ? 1 : 0; - await knex('vehicle_entries').insert({timestamp: new Date().getTime(), direction: direction}); + const direction = 'arrival' === req.params.direction ? 1 : 0; + await knex('vehicle_entries').insert({timestamp: new Date(), direction: direction, event_id: req.params.event_id}); return res.status(200).json({ message: "Vehicle action completed" }); @@ -264,11 +264,11 @@ router.post( ); router.get( - '/vehicle-counter', + '/vehicle-counter/:event_id', async function (req, res) { try { - let vehicleEntries = await knex('vehicle_entries').count().where('direction', '=', 1); - let vehicleExits = await knex('vehicle_entries').count().where('direction', '=', 0); + let vehicleEntries = (await knex('vehicle_entries').count().where('direction', '=', 1))[0]['count(*)']; + let vehicleExits = (await knex('vehicle_entries').count().where('direction', '=', 0))[0]['count(*)']; return res.status(200).json({ vehicleCount: vehicleEntries - vehicleExits }); @@ -279,10 +279,13 @@ router.get( ); router.get( - '/all-vehicle-actions/:dateFrom/:dateTo', + '/all-vehicle-actions/:event_id/:dateFrom/:dateTo', async function (req, res) { try { - let vehicleTimestamps = await knex('vehicle_entries').where('timestamp', '>', req.params.dateFrom).where('timestamp', '<', req.params.dateTo); + let vehicleTimestamps = await knex('vehicle_entries') + .where('event_id', '=', req.params.event_id) + .where('timestamp', '>', new Date(parseInt(req.params.dateFrom))) + .where('timestamp', '<', new Date(parseInt(req.params.dateTo))); return res.status(200).json({ vehicleTimestamps: vehicleTimestamps });