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

@@ -3,61 +3,61 @@ const reportService = require('../services/report.service');
const { logger } = require('../util/logger');
async function active_users(req, res) {
const { from_date, to_date } = req.body;
if (!from_date || !to_date) {
return res.status(400).json({ error: 'from_date and to_date are required' });
}
try {
const users = await reportService.total_users(from_date, to_date);
const activeUsers = users.filter(u => u.is_first_login === false);
const inactiveUsers = users.filter(u => u.is_first_login === true);
const active_user_list = activeUsers.map(u => ({
customer_no: u.customer_no,
user_name: u.preferred_name,
created_at: u.created_at,
last_login: u.last_login,
status: "active"
}));
logger.info(`fetch total number of users and active users from date ${from_date} to ${to_date}`);
res.json({
total_users: users.length,
active_users: activeUsers.length,
inactive_users: inactiveUsers.length,
active_user_list: active_user_list
});
} catch (err) {
logger.error(err, 'failed to fetch data');
res.status(500).json({ error: 'something went wrong' });
}
const { from_date, to_date } = req.body;
if (!from_date || !to_date) {
return res.status(400).json({ error: 'from_date and to_date are required' });
}
try {
const users = await reportService.total_users(from_date, to_date);
const activeUsers = users.filter(u => u.is_first_login === false);
const inactiveUsers = users.filter(u => u.is_first_login === true);
const active_user_list = activeUsers.map(u => ({
customer_no: u.customer_no,
user_name: u.preferred_name,
created_at: u.created_at,
last_login: u.last_login,
status: "active"
}));
logger.info(`fetch total number of users and active users from date ${from_date} to ${to_date}`);
res.json({
total_users: users.length,
active_users: activeUsers.length,
inactive_users: inactiveUsers.length,
active_user_list: active_user_list
});
} catch (err) {
logger.error(err, 'failed to fetch data');
res.status(500).json({ error: 'something went wrong' });
}
}
async function inactive_users(req, res) {
const { from_date, to_date } = req.body;
if (!from_date || !to_date) {
return res.status(400).json({ error: 'from_date and to_date are required' });
}
try {
const users = await reportService.total_users(from_date, to_date);
const activeUsers = users.filter(u => u.is_first_login === false);
const inactiveUsers = users.filter(u => u.is_first_login === true);
const inactive_user_list = inactiveUsers.map(u => ({
customer_no: u.customer_no,
user_name: u.preferred_name,
created_at: u.created_at,
last_login: u.last_login,
status: "in-active"
}));
logger.info(`fetch total number of users and inactive users from date ${from_date} to ${to_date}`);
res.json({
total_users: users.length,
active_users: activeUsers.length,
inactive_users: inactiveUsers.length,
inactive_user_list: inactive_user_list
});
} catch (err) {
logger.error(err, 'failed to fetch data');
res.status(500).json({ error: 'something went wrong' });
}
const { from_date, to_date } = req.body;
if (!from_date || !to_date) {
return res.status(400).json({ error: 'from_date and to_date are required' });
}
try {
const users = await reportService.total_users(from_date, to_date);
const activeUsers = users.filter(u => u.is_first_login === false);
const inactiveUsers = users.filter(u => u.is_first_login === true);
const inactive_user_list = inactiveUsers.map(u => ({
customer_no: u.customer_no,
user_name: u.preferred_name,
created_at: u.created_at,
last_login: u.last_login,
status: "in-active"
}));
logger.info(`fetch total number of users and inactive users from date ${from_date} to ${to_date}`);
res.json({
total_users: users.length,
active_users: activeUsers.length,
inactive_users: inactiveUsers.length,
inactive_user_list: inactive_user_list
});
} catch (err) {
logger.error(err, 'failed to fetch data');
res.status(500).json({ error: 'something went wrong' });
}
}
async function getTransactions(req, res) {
@@ -89,15 +89,15 @@ async function getTransactions(req, res) {
const transactions = await reportService.getTransactions(filters);
const transactions_list = transactions.map(u => ({
customer_no: u.customer_no,
from_account: u.from_account,
to_account: u.to_account,
ifsc_code: u.ifsc_code,
amount :u.amount,
created_at :u.created_at,
trx_type:u.trx_type,
status: u.status,
}));
customer_no: u.customer_no,
from_account: u.from_account,
to_account: u.to_account,
ifsc_code: u.ifsc_code,
amount: u.amount,
created_at: u.created_at,
trx_type: u.trx_type,
status: u.status,
}));
res.json({ count: transactions.length, transactions_list });
@@ -128,15 +128,15 @@ async function getFailedTransactions(req, res) {
const transactions = await reportService.getFailedTransactions(filters);
const transactions_list = transactions.map(u => ({
customer_no: u.customer_no,
from_account: u.from_account,
to_account: u.to_account,
ifsc_code: u.ifsc_code,
amount :u.amount,
created_at :u.created_at,
trx_type:u.trx_type,
status: u.status,
}));
customer_no: u.customer_no,
from_account: u.from_account,
to_account: u.to_account,
ifsc_code: u.ifsc_code,
amount: u.amount,
created_at: u.created_at,
trx_type: u.trx_type,
status: u.status,
}));
res.json({ count: transactions.length, transactions_list });
@@ -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

@@ -2,17 +2,17 @@ const db = require('../config/db');
const { logger } = require('../util/logger');
async function total_users(from_date, to_date) {
try {
const result = await db.query(
`SELECT * FROM users WHERE created_at BETWEEN $1 AND $2`,
[from_date, to_date]
);
logger.info("data fetch for users");
return result.rows;
} catch (err) {
logger.error(err, 'failed to fetch data');
res.status(500).json({ error: 'something went wrong' });
}
try {
const result = await db.query(
`SELECT * FROM users WHERE created_at BETWEEN $1 AND $2`,
[from_date, to_date]
);
logger.info("data fetch for users");
return result.rows;
} catch (err) {
logger.error(err, 'failed to fetch data');
res.status(500).json({ error: 'something went wrong' });
}
}
async function getTransactions(filters) {
@@ -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 };