added two routes for getting and setting the daily limit of users
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user