Dashboard API explorer

/api/administrator/profile (GET)

Account information like email addresses is generated with faker-js it is not real user information.

await global.api.administrator.Profile.get(req)

Returns object

{
  "profileid": "prof_457b65fe64f15ae2",
  "object": "profile",
  "appid": "tests_1656038569",
  "accountid": "acct_61550c4f5eaf2fb3",
  "companyName": null,
  "fullName": "Tracy Weissnat",
  "contactEmail": "Tracy56@gmail.com",
  "displayEmail": null,
  "displayName": null,
  "phone": null,
  "occupation": null,
  "location": null,
  "dob": null,
  "website": null,
  "fields": null,
  "createdAt": "2022-06-24T02:42:49.237Z",
  "updatedAt": "2022-06-24T02:42:49.237Z"
}

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-profileid missing querystring profileid
invalid querystring profileid

NodeJS source (view on github)

const dashboard = require('../../../../index.js')

module.exports = {
  get: async (req) => {
    if (!req.query || !req.query.profileid) {
      throw new Error('invalid-profileid')
    }
    let profile = await dashboard.StorageCache.get(req.query.profileid)
    if (!profile) {
      let profileInfo
      try {
        profileInfo = await dashboard.Storage.Profile.findOne({
          where: {
            profileid: req.query.profileid,
            appid: req.appid || global.appid
          }
        })
      } catch (error) {
      }
      if (!profileInfo) {
        throw new Error('invalid-profileid')
      }
      profile = {}
      for (const field of profileInfo._options.attributes) {
        profile[field] = profileInfo.get(field)
      }
      await dashboard.StorageCache.set(req.query.profileid, profile)
    }
    return profile
  }
}

Test source (view on github)

/* 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)
    })
  })
})