feat: added daily limit feature

This commit is contained in:
2025-10-28 15:44:43 +05:30
parent 9f2f557b03
commit 7757b464b3
14 changed files with 129 additions and 30 deletions

View File

@@ -0,0 +1,28 @@
const db = require('../config/db');
async function getDailyLimit(customerNo, clientType) {
if (clientType !== 'IB' && clientType !== 'MB') {
throw new Error('Invalid client type. IB and MB accepted');
}
let query = '';
if (clientType === 'IB') {
query = `SELECT inb_limit_amount AS daily_limit FROM users WHERE customer_no = $1`;
} else {
query = `SELECT mobile_limit_amount AS daily_limit FROM users WHERE customer_no = $1`;
}
const result = await db.query(query, [customerNo]);
return result.rows[0].daily_limit;
}
async function getUsedLimit(customerNo, clientType) {
if (clientType !== 'IB' && clientType !== 'MB') {
throw new Error('Invalid client type. IB and MB accepted');
}
let query = `SELECT SUM(amount) AS used_limit FROM transactions WHERE created_at BETWEEN CURRENT_DATE AND (CURRENT_DATE + INTERVAL '1 day') AND customer_no = $1 AND client = $2`;
const result = await db.query(query, [customerNo, clientType]);
return result.rows[0].used_limit;
}
module.exports = { getDailyLimit, getUsedLimit };