added two routes for getting and setting the daily limit of users

This commit is contained in:
2025-10-28 17:59:22 +05:30
parent 7757b464b3
commit 654b4ddaf7
4 changed files with 75 additions and 16 deletions

View File

@@ -8,14 +8,14 @@ async function checkLimit(req, res, next) {
const { amount } = req.body;
const { user, client } = req;
const dailyLimit = await getDailyLimit(user, client);
if (!dailyLimit) {
logger.info('NO LIMIT SET FOR CUSTOMER. ALLOWING TRANSACTIONS');
next();
}
const usedLimit = await getUsedLimit(user, client);
const remainingLimit = dailyLimit - usedLimit;
logger.info(
`dailyLimit = ${dailyLimit} | usedLimit = ${usedLimit} | remainingLimit = ${remainingLimit}`
);
if (amount > remainingLimit) {
const midnight = new Date();
midnight.setHours(24, 0, 0, 0);