diff --git a/controllers/user.ctl.js b/controllers/user.ctl.js index 250dcbe..851f544 100644 --- a/controllers/user.ctl.js +++ b/controllers/user.ctl.js @@ -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 */ diff --git a/routes/user.js b/routes/user.js index 5bbe4c6..77e3d7e 100644 --- a/routes/user.js +++ b/routes/user.js @@ -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; \ No newline at end of file