Compare commits

...

4 Commits

Author SHA1 Message Date
Sam Machin
fcff3d4b32 add proxy detail from registered client (#458) 2025-06-02 08:08:48 -04:00
Hoan Luu Huu
2dd06df641 Fix Application Model Pagination Issue with LEFT JOINs (#461) 2025-06-01 08:31:27 -04:00
Hoan Luu Huu
579a586a03 fixed filter for carriers for an account (#460)
* fixed filter for carriers for an account

* wip

* wip
2025-05-30 07:24:55 -04:00
Hoan Luu Huu
3e1b383284 fix microsoft fetch list voice from hardcode westus region (#459) 2025-05-29 10:07:58 -04:00
5 changed files with 68 additions and 14 deletions

View File

@@ -75,17 +75,59 @@ class Application extends Model {
*/
static retrieveAll(obj) {
const { page, page_size = 50 } = obj || {};
// If pagination is requested, first get the application IDs
if (page !== null && page !== undefined) {
let idSql = 'SELECT application_sid, name FROM applications app WHERE 1 = 1';
const idArgs = [];
idSql += Application._criteriaBuilder(obj, idArgs);
idSql += ' ORDER BY app.name';
const limit = Number(page_size);
const offset = Number(page > 0 ? (page - 1) : page) * limit;
idSql += ' LIMIT ? OFFSET ?';
idArgs.push(limit);
idArgs.push(offset);
return new Promise((resolve, reject) => {
getMysqlConnection((err, conn) => {
if (err) return reject(err);
// Get paginated application IDs
conn.query(idSql, idArgs, (err, idResults) => {
if (err) {
conn.release();
return reject(err);
}
if (idResults.length === 0) {
conn.release();
return resolve([]);
}
// Get full data for these applications
const appIds = idResults.map((row) => row.application_sid);
const placeholders = appIds.map(() => '?').join(',');
const fullSql = `${retrieveSql}
WHERE app.application_sid IN (${placeholders}) ORDER BY app.name`;
conn.query({sql: fullSql, nestTables: true}, appIds, (err, results) => {
conn.release();
if (err) return reject(err);
const r = transmogrifyResults(results);
resolve(r);
});
});
});
});
}
// No pagination - use original query
let sql = retrieveSql + ' WHERE 1 = 1';
const args = [];
sql += Application._criteriaBuilder(obj, args);
sql += ' ORDER BY app.application_sid';
if (page !== null && page !== undefined) {
const limit = Number(page_size);
const offset = Number(page > 0 ? (page - 1) : page) * limit;
sql += ' LIMIT ? OFFSET ?';
args.push(limit);
args.push(offset);
}
return new Promise((resolve, reject) => {
getMysqlConnection((err, conn) => {
if (err) return reject(err);

View File

@@ -12,10 +12,15 @@ class VoipCarrier extends Model {
static _criteriaBuilder(obj, args) {
let sql = '';
if (obj.account_sid) {
sql += ' AND vc.account_sid = ?';
// carrier belong to an account when
// 1. account_sid is set
// 2. account_sid is null and service_provider_sid matches the account's service_provider_sid
sql += ` AND (vc.account_sid = ? OR
(vc.account_sid IS NULL AND vc.service_provider_sid IN
(SELECT service_provider_sid FROM accounts WHERE account_sid = ?))
)`;
args.push(obj.account_sid);
args.push(obj.account_sid);
} else {
sql += ' AND vc.account_sid IS NULL';
}
if (obj.service_provider_sid) {
sql += ' AND vc.service_provider_sid = ?';

View File

@@ -248,7 +248,8 @@ router.get('/:sid/RegisteredSipUsers/:client', async(req, res) => {
allow_direct_app_calling: clientDb ? clientDb.allow_direct_app_calling : 0,
allow_direct_queue_calling: clientDb ? clientDb.allow_direct_queue_calling : 0,
allow_direct_user_calling: clientDb ? clientDb.allow_direct_user_calling : 0,
registered_status: user ? 'active' : 'inactive'
registered_status: user ? 'active' : 'inactive',
proxy: user ? user.proxy : null
});
} catch (err) {
sysError(logger, res, err);

View File

@@ -97,13 +97,18 @@ decorate(router, PhoneNumber, ['add', 'update', 'delete'], preconditions);
/* list */
router.get('/', async(req, res) => {
const logger = req.app.locals.logger;
const {account_sid: query_account_sid, filter, page, page_size} = req.query;
const {service_provider_sid: query_service_provider_sid,
account_sid: query_account_sid, filter, page, page_size} = req.query;
const isPaginationRequest = page !== null && page !== undefined;
let service_provider_sid = null, account_sid = query_account_sid;
if (req.user.hasAccountAuth) {
account_sid = req.user.account_sid;
} else if (req.user.hasServiceProviderAuth) {
service_provider_sid = req.user.service_provider_sid;
} else {
// admin user can query all phone numbers
service_provider_sid = query_service_provider_sid;
account_sid = query_account_sid;
}
try {
let total = 0;

View File

@@ -822,9 +822,10 @@ async function getLanguagesVoicesForAws(credential, getTtsVoices, logger) {
async function getLanguagesVoicesForMicrosoft(credential, getTtsVoices, logger) {
if (credential) {
const response = await fetch('https://westus.tts.speech.microsoft.com/cognitiveservices/voices/list', {
const {region, api_key} = credential;
const response = await fetch(`https://${region}.tts.speech.microsoft.com/cognitiveservices/voices/list`, {
headers: {
'Ocp-Apim-Subscription-Key': credential.api_key
'Ocp-Apim-Subscription-Key': api_key
}
});
if (!response.ok) {