Skip to content

Commit

Permalink
Merge pull request #7 from codewith-zach/master
Browse files Browse the repository at this point in the history
search api
  • Loading branch information
mrvincentoti authored Aug 29, 2022
2 parents 34a9d1f + a5771ff commit 7275a2f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
25 changes: 24 additions & 1 deletion api/users/user.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const {
getUsers,
createUsers,
getVisitorPurpose,
getAllVisitors
getAllVisitors,
getVisitorByFullname

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

const { genSaltSync, hashSync, compareSync} = require('bcrypt');//importing bcrypt
Expand Down Expand Up @@ -189,6 +191,27 @@ module.exports = {
});
});
},
getVisitorByFullname: (req, res) => {
const fullname = req.query.fullname;
console.log(fullname);

getVisitorByFullname(fullname, (err, results) => {
if (err) {
console.log(err);
return;
}
if (!results) {
return res.json({
success: 0,
message: "Record not Found"
});
}
return res.json({
success: 1,
data: results
});
});
},
updateUser: (req, res) => {
const body = req.body;
console.log(body);
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 @@ -11,7 +11,8 @@ const { //We have to import all the controllers in the router
getUsers,
createUsers,
getVisitorPurpose,
getAllVisitors
getAllVisitors,
getVisitorByFullname
} = require('./user.controller');

const router = require('express').Router();
Expand All @@ -33,5 +34,6 @@ router.post('/user/login', login); //used for login
router.get('/user/getUsers', getUsers);
router.post('/user/createUsers', checkToken, createUsers);
router.get('/visitor/getVisitorPurpose', getVisitorPurpose);
router.get('/visitor/getVisitorByFullname', getVisitorByFullname);

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 @@ -164,6 +164,25 @@ module.exports = {
}
);
},
getVisitorByFullname: (fullname, 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 v.fullname like '%${fullname}%'
`,
[fullname],
(error, results, fields) => {
if (error) {
callBack(error);
}
return callBack(null, results[0]);
}
);
},
updateVisitors: (data, callBack) => {
pool.query(
`update visitors set fullname=?, user_id=?, purpose_id=?, date_added=?, address=? where id=?`,
Expand Down

0 comments on commit 7275a2f

Please sign in to comment.