feat/367 added support for name query parameter for retrieving application (#368)

* feat/367 added support for name query parameter for getting application by name

* feat/367 - Updated test case and modified retrieveAll method to make name independent of service_provider_id and account_sid

* updated query to use WHERE 1=1 to avoid whereFlag variable

* feat/367: removed empty line added accidently
This commit is contained in:
rammohan-y
2024-12-18 18:48:48 +05:30
committed by GitHub
parent e080118b6a
commit 8851b3fac0
3 changed files with 31 additions and 6 deletions

View File

@@ -37,19 +37,24 @@ class Application extends Model {
}
/**
* list all applications - for all service providers, for one service provider, or for one account
* list all applications - for all service providers, for one service provider, or for one account,
* or by an optional name
*/
static retrieveAll(service_provider_sid, account_sid) {
let sql = retrieveSql;
static retrieveAll(service_provider_sid, account_sid, name) {
let sql = retrieveSql + ' WHERE 1 = 1';
const args = [];
if (account_sid) {
sql = `${sql} WHERE app.account_sid = ?`;
sql = `${sql} AND app.account_sid = ?`;
args.push(account_sid);
}
else if (service_provider_sid) {
sql = `${sql} WHERE account_sid in (SELECT account_sid from accounts WHERE service_provider_sid = ?)`;
sql = `${sql} AND account_sid in (SELECT account_sid from accounts WHERE service_provider_sid = ?)`;
args.push(service_provider_sid);
}
if (name) {
sql = `${sql} AND app.name = ?`;
args.push(name);
}
return new Promise((resolve, reject) => {
getMysqlConnection((err, conn) => {
if (err) return reject(err);