Skip to content

Commit

Permalink
added visitorcount endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Abzmoni committed Sep 1, 2022
1 parent d504f64 commit 9e717d0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
15 changes: 14 additions & 1 deletion api/users/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ const {
createUsers,
getVisitorPurpose,
getAllVisitors,
getVisitorByFullname
getVisitorByFullname,
getVisitorsNumber

} = require('./user.service'); //we called the service

Expand Down Expand Up @@ -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) => {
Expand Down
4 changes: 3 additions & 1 deletion api/users/user.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
19 changes: 19 additions & 0 deletions api/users/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
`
Expand Down

0 comments on commit 9e717d0

Please sign in to comment.