Skip to content

Commit

Permalink
clock-out endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
codewith-zach committed Aug 29, 2022
1 parent a5771ff commit 23d902f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 3 deletions.
26 changes: 24 additions & 2 deletions 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,
updateVisitorClockout

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

Expand Down Expand Up @@ -75,7 +76,6 @@ module.exports = {
});
});
},

updateVisitors: (req, res) => {
const body = req.body;
console.log(body);
Expand All @@ -97,6 +97,28 @@ module.exports = {
message: 'updated successfully'
});
});
},
updateVisitorClockout: (req, res) => {
const body = req.body;
console.log(body);
// const salt = genSaltSync(10);
// body.password = hashSync(body.password, salt);
updateVisitorClockout(body, (err, results) => {
if (err) {
console.log(err);
return;
}
if(!results){
return res.json({
success: 0,
message: 'failed to update visitor'
});
}
return res.json({
success: 1,
message: 'updated successfully'
});
});
},
deleteVisitors: (req, res) => {
const data = req.body;
Expand Down
6 changes: 5 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,
updateVisitorClockout
} = require('./user.controller');

const router = require('express').Router();
Expand All @@ -35,5 +36,8 @@ router.get('/user/getUsers', getUsers);
router.post('/user/createUsers', checkToken, createUsers);
router.get('/visitor/getVisitorPurpose', getVisitorPurpose);
router.get('/visitor/getVisitorByFullname', getVisitorByFullname);
router.patch('/visitor/updateVisitorClockout', updateVisitorClockout);



module.exports = router;
17 changes: 17 additions & 0 deletions api/users/user.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ module.exports = {
}
);
},



getVisitorPurpose: callBack => {
pool.query(
`select id, purpose from purpose`,
Expand Down Expand Up @@ -202,6 +205,20 @@ module.exports = {
}
);
},
updateVisitorClockout: (data, callBack) => {
pool.query(
`update clock_in set time_out = now() where visitor_id=? `,
[
data.visitor_id
],
(error, results, fields) =>{
if (error) {
callBack(error);
}
return callBack(null, results);
}
);
},
deleteVisitors: (data, callBack) => {
pool.query(
`delete from visitors where id = ?`,
Expand Down

0 comments on commit 23d902f

Please sign in to comment.