Dashboard API explorer

/api/administrator/profile (GET)

await global.api.administrator.Profile.get(req)
Located in Dashboard API

Returns object

Exceptions

These exceptions are thrown (NodeJS) or returned as JSON (HTTP) if you provide incorrect data or do not meet the requirements:

Exception Circumstances
invalid querystring profileid
invalid-profileid missing querystring profileid

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 = {
  get: async (req) => {
    if (!req.query || !req.query.profileid) {
      throw new Error('invalid-profileid')
    }
    const storage = req.storage || dashboard
    let profile
    if (req.cacheData && req.cacheData[req.query.profileid]) {
      profile = req.cacheData[req.query.profileid]
    } else {
      profile = await storage.Storage.read(`${req.appid}/profile/${req.query.profileid}`)
    }
    if (!profile) {
      throw new Error('invalid-profileid')
    }
    try {
      profile = JSON.parse(profile)
    } catch (error) {
    }
    if (!profile || profile.object !== 'profile') {
      throw new Error('invalid-profileid')
    }
    return profile
  }
}

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/profile', () => {
  describe('exceptions', () => {
    describe('invalid-profileid', () => {
      it('missing querystring profileid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/profile')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-profileid')
      })

      it('invalid querystring profileid', async () => {
        const administrator = await TestHelper.createOwner()
        const req = TestHelper.createRequest('/api/administrator/profile?profiled=invalid')
        req.account = administrator.account
        req.session = administrator.session
        let errorMessage
        try {
          await req.get()
        } catch (error) {
          errorMessage = error.message
        }
        assert.strictEqual(errorMessage, 'invalid-profileid')
      })
    })
  })

  describe('returns', () => {
    it('object', async () => {
      const administrator = await TestHelper.createOwner()
      const user = await TestHelper.createUser()
      const req = TestHelper.createRequest(`/api/administrator/profile?profileid=${user.profile.profileid}`)
      req.account = administrator.account
      req.session = administrator.session
      req.filename = __filename
      req.saveResponse = true
      const profile = await req.get()
      assert.strictEqual(profile.profileid, user.account.profileid)
    })
  })
})