mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2025-12-19 05:47:46 +00:00
Feature/sp call limits (#63)
* add api for setting/querying call limits by account and sp * update an account or sp limit if one exists rather than creating a new one
This commit is contained in:
@@ -1,9 +1,17 @@
|
||||
const Model = require('./model');
|
||||
const {promisePool} = require('../db');
|
||||
const sql = 'SELECT * FROM account_limits WHERE account_sid = ?';
|
||||
|
||||
class AccountLimits extends Model {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
|
||||
static async retrieve(account_sid) {
|
||||
const [rows] = await promisePool.query(sql, [account_sid]);
|
||||
return rows;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
AccountLimits.table = 'account_limits';
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
const Model = require('./model');
|
||||
const {promisePool} = require('../db');
|
||||
const sql = 'SELECT * FROM service_provider_limits WHERE service_provider_sid = ?';
|
||||
|
||||
class ServiceProviderLimits extends Model {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
static async retrieve(service_provider_sid) {
|
||||
const [rows] = await promisePool.query(sql, [service_provider_sid]);
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
ServiceProviderLimits.table = 'service_provider_limits';
|
||||
|
||||
@@ -40,7 +40,7 @@ router.post('/', async(req, res) => {
|
||||
try {
|
||||
let uuid;
|
||||
if (account_sid) {
|
||||
const existing = (await AccountLimits.retrieveAll(account_sid) || [])
|
||||
const existing = (await AccountLimits.retrieve(account_sid) || [])
|
||||
.find((el) => el.category === category);
|
||||
if (existing) {
|
||||
uuid = existing.account_limits_sid;
|
||||
@@ -55,7 +55,7 @@ router.post('/', async(req, res) => {
|
||||
}
|
||||
}
|
||||
else {
|
||||
const existing = (await ServiceProviderLimits.retrieveAll(service_provider_sid) || [])
|
||||
const existing = (await ServiceProviderLimits.retrieve(service_provider_sid) || [])
|
||||
.find((el) => el.category === category);
|
||||
if (existing) {
|
||||
uuid = existing.service_provider_limits_sid;
|
||||
@@ -85,8 +85,8 @@ router.get('/', async(req, res) => {
|
||||
const logger = req.app.locals.logger;
|
||||
try {
|
||||
const limits = account_sid ?
|
||||
await AccountLimits.retrieveAll(account_sid) :
|
||||
await ServiceProviderLimits.retrieveAll(service_provider_sid);
|
||||
await AccountLimits.retrieve(account_sid) :
|
||||
await ServiceProviderLimits.retrieve(service_provider_sid);
|
||||
|
||||
if (req.query?.category) {
|
||||
return res.status(200).json(limits.filter((el) => el.category === req.query.category));
|
||||
|
||||
@@ -159,6 +159,7 @@ test('service provider tests', async(t) => {
|
||||
auth: authAdmin,
|
||||
json: true,
|
||||
});
|
||||
//console.log(result);
|
||||
t.ok(result.length === 1 , 'successfully queried all limits');
|
||||
|
||||
/* delete call session limits for a service provider */
|
||||
|
||||
Reference in New Issue
Block a user