feat: added daily limit feature
This commit is contained in:
28
src/services/paymentLimit.service.js
Normal file
28
src/services/paymentLimit.service.js
Normal 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 };
|
||||
Reference in New Issue
Block a user