/api/administrator/accounts (GET)
await global.api.administrator.Accounts.get(req) Located in Dashboard API
Returns array
Exceptions
These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:
Exception | Circumstances |
---|
Receives
API routes may receive parameters from the URL and POST supporting simple and multipart:
Field | Value | Required | Type |
---|---|---|---|
all | boolean | optional | URL |
limit | integer | optional | URL |
offset | integer | optional | URL |
NodeJS source (edit on github)
If you see a problem with the source submit a pull request on Github.
const dashboard = require('../../../../index.js')
module.exports = {
/**
* Returns a list of users bound to profile information
*/
get: async (req) => {
req.query = req.query || {}
let accountids
if (req.query.all) {
accountids = await dashboard.StorageList.listAll(`${req.appid}/accounts`)
} else {
const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
accountids = await dashboard.StorageList.list(`${req.appid}/accounts`, offset, limit)
}
if (!accountids || !accountids.length) {
return null
}
req.cacheData = await dashboard.Storage.readMany(`${req.appid}/account`, accountids)
const accounts = []
for (const accountid of accountids) {
req.query.accountid = accountid
const account = await global.api.administrator.Account.get(req)
accounts.push(account)
}
return accounts
}
}
Test source (edit on github)
Tests perform real HTTP requests against a running Dashboard server.
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../test-helper.js')
describe('/api/administrator/accounts', function () {
const cachedResponses = {}
const cachedAccounts = []
before(async () => {
await TestHelper.setupBeforeEach()
const administrator = await TestHelper.createUser()
cachedAccounts.push(administrator.account.accountid)
global.delayDiskWrites = true
for (let i = 0, len = global.pageSize + 1; i < len; i++) {
const user = await TestHelper.createUser()
cachedAccounts.unshift(user.account.accountid)
}
const req1 = TestHelper.createRequest('/api/administrator/accounts?offset=1')
req1.account = administrator.account
req1.session = administrator.session
cachedResponses.offset = await req1.get()
const req2 = TestHelper.createRequest('/api/administrator/accounts?limit=1')
req2.account = administrator.account
req2.session = administrator.session
cachedResponses.limit = await req2.get()
const req3 = TestHelper.createRequest('/api/administrator/accounts?all=true')
req3.account = administrator.account
req3.session = administrator.session
cachedResponses.all = await req3.get()
const req4 = TestHelper.createRequest('/api/administrator/accounts')
req4.account = administrator.account
req4.session = administrator.session
req4.filename = __filename
req4.saveResponse = true
cachedResponses.returns = await req4.get()
global.pageSize = 3
cachedResponses.pageSize = await req4.get()
})
describe('receives', () => {
it('optional querystring offset (integer)', async () => {
const offset = 1
const accountsNow = cachedResponses.offset
for (let i = 0, len = global.pageSize; i < len; i++) {
assert.strictEqual(accountsNow[i].accountid, cachedAccounts[offset + i])
}
})
it('optional querystring limit (integer)', async () => {
const limit = 1
const accountsNow = cachedResponses.limit
assert.strictEqual(accountsNow.length, limit)
})
it('optional querystring all (boolean)', async () => {
const accountsNow = cachedResponses.all
assert.strictEqual(accountsNow.length, cachedAccounts.length)
})
})
describe('returns', () => {
it('array', async () => {
const accountsNow = cachedResponses.returns
assert.strictEqual(accountsNow.length, global.pageSize)
})
})
describe('redacts', () => {
it('usernameHash', async () => {
const accounts = cachedResponses.returns
assert.strictEqual(accounts[0].usernameHash, undefined)
})
it('passwordHash', async () => {
const accounts = cachedResponses.returns
assert.strictEqual(accounts[0].passwordHash, undefined)
})
it('sessionKey', async () => {
const accounts = cachedResponses.returns
assert.strictEqual(accounts[0].sessionKey, undefined)
})
})
describe('configuration', () => {
it('environment PAGE_SIZE', async () => {
global.pageSize = 3
const accountsNow = cachedResponses.pageSize
assert.strictEqual(accountsNow.length, global.pageSize)
})
})
})