-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from jambonz/feat/send_options_ping
send options ping
- Loading branch information
Showing
8 changed files
with
136 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const debug = require('debug')('jambonz:db-helpers'); | ||
|
||
/** | ||
* Lookup sip gateways by arbitrary filters | ||
* @param {mysql.Pool} pool | ||
* @param {Object} logger | ||
* @param {Object} filters - An object of column names and values to filter on. | ||
*/ | ||
async function lookupSipGatewaysByFilters(pool, logger, filters) { | ||
const pp = pool.promise(); | ||
|
||
let sql = 'SELECT * FROM sip_gateways WHERE '; | ||
const params = []; | ||
for (const [key, value] of Object.entries(filters)) { | ||
sql += `${key} = ? AND `; | ||
params.push(value); | ||
} | ||
|
||
// Remove trailing ' AND ' | ||
sql = sql.slice(0, -5); | ||
|
||
const [r] = await pp.execute(sql, params); | ||
debug(`results: ${JSON.stringify(r)}`); | ||
return r; | ||
} | ||
|
||
module.exports = lookupSipGatewaysByFilters; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
const debug = require('debug')('jambonz:db-helpers'); | ||
|
||
/** | ||
* Update a sip gateway given its sid and an object of values. | ||
* @param {mysql.Pool} pool | ||
* @param {Object} logger | ||
* @param {string} sip_gateway_sid - The sid of the gateway to update. | ||
* @param {Object} values - An object where each key-value pair represents a column name and a new value. | ||
*/ | ||
async function updateSipGatewayBySid(pool, logger, sip_gateway_sid, values) { | ||
const pp = pool.promise(); | ||
|
||
// Begin building the SQL query string and parameters. | ||
let sql = 'UPDATE sip_gateways SET '; | ||
const params = []; | ||
for (const [key, value] of Object.entries(values)) { | ||
sql += `${key} = ?, `; | ||
params.push(value); | ||
} | ||
|
||
// Remove trailing comma and space | ||
sql = sql.slice(0, -2); | ||
|
||
// Add WHERE clause | ||
sql += ' WHERE sip_gateway_sid = ?'; | ||
params.push(sip_gateway_sid); | ||
|
||
const [r] = await pp.execute(sql, params); | ||
debug(`results: ${JSON.stringify(r)}`); | ||
return r; | ||
} | ||
|
||
module.exports = updateSipGatewayBySid; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters