feat : List of who are not login in mentioned time duration

This commit is contained in:
2025-11-14 13:22:13 +05:30
parent 3262ff53bf
commit 12750e833c
3 changed files with 127 additions and 84 deletions

View File

@@ -146,4 +146,33 @@ async function getFailedTransactions(req, res) {
}
}
module.exports = { active_users ,inactive_users, getTransactions ,getFailedTransactions };
async function getDetailsOfNotLoginWithinDuration(req, res) {
const {
duration
} = req.body;
if (!duration) {
return res.status(400).json({ error: 'Duration are required' });
}
try {
const users = await reportService.getNotLogin(duration);
const user_list = users.map(u => ({
customer_no: u.customer_no,
user_name: u.preferred_name,
last_login: u.last_login,
created_at: u.created_at,
locked: u.locked,
status: u.status,
}));
res.json({ count: users.length, user_list });
} catch (err) {
logger.error(err, 'failed to fetch not logged in user details');
res.status(500).json({ error: 'something went wrong' });
}
}
module.exports = { active_users, inactive_users, getTransactions, getFailedTransactions, getDetailsOfNotLoginWithinDuration };

View File

@@ -7,5 +7,6 @@ router.post('/active_users', reportController.active_users);
router.post('/in-active_users', reportController.inactive_users);
router.post('/transaction_report', reportController.getTransactions);
router.post('/failed_transaction_report', reportController.getFailedTransactions);
router.post('/not_logged_in', reportController.getDetailsOfNotLoginWithinDuration);
module.exports = router;

View File

@@ -89,5 +89,18 @@ async function getFailedTransactions(filters) {
}
}
async function getNotLogin(duration) {
try {
const result = await db.query(
`SELECT * FROM users WHERE last_login <= NOW() - ($1 || ' month')::interval`,
[duration]
);
logger.info("data fetch for users who have not logged-in in mentioned duration");
return result.rows;
} catch (err) {
logger.error(err, 'failed to fetch not logged-in users data');
res.status(500).json({ error: 'something went wrong' });
}
}
module.exports = { total_users ,getTransactions ,getFailedTransactions };
module.exports = { total_users, getTransactions, getFailedTransactions, getNotLogin };