Skip to content

Commit

Permalink
Merge pull request #33 from deevanshu-k/userRouteGetDetails
Browse files Browse the repository at this point in the history
ADD: user.ctl.getUserDetails + Route GET /api/user/details
  • Loading branch information
deevanshu-k authored Dec 22, 2023
2 parents 17ea232 + e923de2 commit 23672f6
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
37 changes: 37 additions & 0 deletions controllers/user.ctl.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,43 @@ userControllers.getUserDocuments = async (req, res) => {
}
}

userControllers.getUserDetails = async (req, res) => {
try {
const { role, id } = req.user;
let userdetails = {};

if (role === 'TENANT') {
userdetails = await db.tenant.findOne({
where: { id: id },
attributes: ['id', 'username', 'email', 'phone_no', 'key', 'profile_image', 'address', 'verification_status']
});
}
else if (role === 'LANDLORD') {
userdetails = await db.landlord.findOne({
where: { id: id },
attributes: ['id', 'username', 'email', 'phone_no', 'key', 'profile_image', 'address', 'verification_status']
});
}
else if (role === 'ADMIN') {
userdetails = await db.admin.findOne({
where: { id: id },
attributes: ['id', 'username', 'email', 'key', 'profile_image']
});
}

return res.status(Constant.SUCCESS_CODE).json({
code: Constant.SUCCESS_CODE,
data: userdetails
});
} catch (error) {
console.log(error);
return res.status(Constant.SERVER_ERROR).json({
code: Constant.SERVER_ERROR,
message: Constant.SOMETHING_WENT_WRONG
})
}
}

/*
Admin Controller Methods
*/
Expand Down
1 change: 1 addition & 0 deletions routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ const rateLimiter = require("../middileware/rate-limit");
const auth = require("../middileware/auth");

router.get("/documents", rateLimiter.commonOperationsRouteRateLimiter, auth.checkAuthentication, userControllers.getUserDocuments);
router.get("/details", rateLimiter.commonOperationsRouteRateLimiter, auth.checkAuthentication, userControllers.getUserDetails);

module.exports = router;

0 comments on commit 23672f6

Please sign in to comment.