diff --git a/api/users/user.controller.js b/api/users/user.controller.js index c81a31a..5bd66de 100644 --- a/api/users/user.controller.js +++ b/api/users/user.controller.js @@ -14,7 +14,8 @@ const { createUsers, getVisitorPurpose, getAllVisitors, - getVisitorByFullname + getVisitorByFullname, + getVisitorsNumber } = require('./user.service'); //we called the service @@ -159,6 +160,18 @@ module.exports = { data: results }); }); +}, +getVisitorsNumber: (req, res) => { + getVisitorsNumber((err, results) => { + if (err) { + console.log(err); + return; + } + return res.json({ + success: 1, + data: results + }); + }); }, getVisitorPurpose: (req, res) => { getVisitorPurpose((err, results) => { diff --git a/api/users/user.router.js b/api/users/user.router.js index f25c9b1..a5900c2 100644 --- a/api/users/user.router.js +++ b/api/users/user.router.js @@ -12,7 +12,8 @@ const { //We have to import all the controllers in the router createUsers, getVisitorPurpose, getAllVisitors, - getVisitorByFullname + getVisitorByFullname, + getVisitorsNumber } = require('./user.controller'); const router = require('express').Router(); @@ -35,5 +36,6 @@ router.get('/user/getUsers', getUsers); router.post('/user/createUsers', checkToken, createUsers); router.get('/visitor/getVisitorPurpose', getVisitorPurpose); router.get('/visitor/getVisitorByFullname', getVisitorByFullname); +router.get('/visitor/getVisitorsNumber', checkToken, getVisitorsNumber); module.exports = router; \ No newline at end of file diff --git a/api/users/user.service.js b/api/users/user.service.js index 6236e49..337e07e 100644 --- a/api/users/user.service.js +++ b/api/users/user.service.js @@ -77,6 +77,25 @@ module.exports = { } ); }, + getVisitorsNumber: callBack => { + pool.query( + ` + select v.id as id, v.fullname as fullname, v.purpose_id as purpose, v.date_added as date_added, v.address as address, + c.time_in as time_in, c.time_out as time_out,u.first_name as first_name, u.last_name as last_name + from clock_in c + join visitors v on v.id = c.visitor_id + join users u on u.id = v.user_id + where date(c.time_in) = current_date + `, + [], + (error, results, fields) => { + if (error) { + return callBack(error); + } + return callBack(null, results); + } + ); + }, getAllVisitors: callBack => { pool.query( `