mirror of
https://github.com/jambonz/jambonz-api-server.git
synced 2026-10-31 20:04:18 +00:00
more authentication tests
This commit is contained in:
1 parent
10354816f2
commit
760e0f53aa
5 files changed
+169
-24
No files matched your search
@@ -1,11 +1,23 @@
|
||||
const Model = require('./model');
|
||||
const {getMysqlConnection} = require('../db');
|
||||
const serviceProviderSql = `
|
||||
SELECT * from ${this.table}
|
||||
const listSqlSp = `
|
||||
SELECT * from applications
|
||||
WHERE account_sid in (
|
||||
SELECT account_sid from accounts
|
||||
WHERE service_provider_sid = ?
|
||||
)`;
|
||||
const listSqlAccount = 'SELECT * from applications WHERE account_sid = ?';
|
||||
const retrieveSqlSp = `
|
||||
SELECT * from applications
|
||||
WHERE account_sid in (
|
||||
SELECT account_sid from accounts
|
||||
WHERE service_provider_sid = ?
|
||||
)
|
||||
AND application_sid = ?`;
|
||||
const retrieveSqlAccount = `
|
||||
SELECT * from applications
|
||||
WHERE account_sid = ?
|
||||
AND application_sid = ?`;
|
||||
|
||||
class Application extends Model {
|
||||
constructor() {
|
||||
@@ -13,13 +25,16 @@ class Application extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve all applications for an account
|
||||
* list all applications - for all service providers, for one service provider, or for one account
|
||||
*/
|
||||
static retrieveAllForAccount(account_sid) {
|
||||
static retrieveAll(service_provider_sid, account_sid) {
|
||||
if (!service_provider_sid && !account_sid) return super.retrieveAll();
|
||||
return new Promise((resolve, reject) => {
|
||||
getMysqlConnection((err, conn) => {
|
||||
if (err) return reject(err);
|
||||
conn.query(`SELECT * from ${this.table} WHERE account_sid = ?`, [account_sid], (err, results, fields) => {
|
||||
const sql = account_sid ? listSqlAccount : listSqlSp;
|
||||
const args = account_sid ? [account_sid] : [service_provider_sid];
|
||||
conn.query(sql, args, (err, results, fields) => {
|
||||
conn.release();
|
||||
if (err) return reject(err);
|
||||
resolve(results);
|
||||
@@ -29,13 +44,16 @@ class Application extends Model {
|
||||
}
|
||||
|
||||
/**
|
||||
* retrieve all applications for a service provider
|
||||
* retrieve an application
|
||||
*/
|
||||
static retrieveAllForServiceProvider(service_provider_sid) {
|
||||
static retrieve(sid, service_provider_sid, account_sid) {
|
||||
if (!service_provider_sid && !account_sid) return super.retrieve(sid);
|
||||
return new Promise((resolve, reject) => {
|
||||
getMysqlConnection((err, conn) => {
|
||||
if (err) return reject(err);
|
||||
conn.query(serviceProviderSql, [service_provider_sid], (err, results, fields) => {
|
||||
const sql = account_sid ? retrieveSqlAccount : retrieveSqlSp;
|
||||
const args = account_sid ? [account_sid, sid] : [service_provider_sid, sid];
|
||||
conn.query(sql, args, (err, results, fields) => {
|
||||
conn.release();
|
||||
if (err) return reject(err);
|
||||
resolve(results);
|
||||
@@ -43,6 +61,7 @@ class Application extends Model {
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Application.table = 'applications';
|
||||
|
||||
Reference in new issue
Block a user