Skip to content

Commit

Permalink
Merge pull request #10 from Abzmoni/master
Browse files Browse the repository at this point in the history
added visitor count endpoint
  • Loading branch information
mrvincentoti authored Sep 1, 2022
2 parents f6a93e6 + 4331993 commit 6124310
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
15 changes: 14 additions & 1 deletion api/users/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const {
getVisitorPurpose,
getAllVisitors,
getVisitorByFullname,
updateVisitorClockout
updateVisitorClockout,
getVisitorsNumber

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

Expand Down Expand Up @@ -178,6 +179,18 @@ updateVisitorClockout: (req, res) => {
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
2 changes: 2 additions & 0 deletions api/users/user.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const { //We have to import all the controllers in the router
getVisitorPurpose,
getAllVisitors,
getVisitorByFullname,
getVisitorsNumber,
updateVisitorClockout
} = require('./user.controller');

Expand All @@ -36,6 +37,7 @@ 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);
router.patch('/visitor/updateVisitorClockout', updateVisitorClockout);


Expand Down
19 changes: 19 additions & 0 deletions api/users/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,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 6124310

Please sign in to comment.