Organizations module API explorer

/api/administrator/organizations/organizations (GET)

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

await global.api.administrator.organizations.Organizations.get(req)

Returns array

[
  {
    "organizationid": "orgn_93147d3ee44f5d88",
    "object": "organization",
    "appid": "tests_1656039699",
    "ownerid": "acct_615573a0995983f4",
    "name": "My organization 1",
    "pin": "12342",
    "email": "Nicole.Heller@yahoo.com",
    "createdAt": "2022-06-24T03:01:39.531Z",
    "updatedAt": "2022-06-24T03:01:39.531Z"
  },
  {
    "organizationid": "orgn_3e1291bfdb64fe38",
    "object": "organization",
    "appid": "tests_1656039699",
    "ownerid": "acct_615573a0995983f4",
    "name": "My organization 1",
    "pin": "12341",
    "email": "Nicole.Heller@yahoo.com",
    "createdAt": "2022-06-24T03:01:39.511Z",
    "updatedAt": "2022-06-24T03:01:39.511Z"
  },
  {
    "organizationid": "orgn_78a2ad82a75611a1",
    "object": "organization",
    "appid": "tests_1656039699",
    "ownerid": "acct_615573a0995983f4",
    "name": "My organization 1",
    "pin": "12340",
    "email": "Nicole.Heller@yahoo.com",
    "createdAt": "2022-06-24T03:01:39.493Z",
    "updatedAt": "2022-06-24T03:01:39.493Z"
  }
]

Receives

API routes may receive parameters from the URL and POST supporting simple and multipart:

Field Value Required Type
accountid string optional URL
all boolean optional URL
limit integer optional URL
offset integer optional URL

NodeJS source (view on github)

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

module.exports = {
  get: async (req) => {
    req.query = req.query || {}
    const where = {
      appid: req.appid || global.appid
    }
    if (req.query.accountid) {
      where.ownerid = req.query.accountid
    }
    let organizationids
    if (req.query.all) {
      organizationids = await organizations.Storage.Organization.findAll({
        where,
        attributes: ['organizationid'],
        order: [
          ['createdAt', 'DESC']
        ]
      })
    } else {
      const offset = req.query.offset ? parseInt(req.query.offset, 10) : 0
      const limit = req.query.limit ? parseInt(req.query.limit, 10) : global.pageSize
      organizationids = await organizations.Storage.Organization.findAll({
        where,
        attributes: ['organizationid'],
        order: [
          ['createdAt', 'DESC']
        ],
        offset,
        limit
      })
    }
    if (!organizationids || !organizationids.length) {
      return null
    }
    const items = []
    for (const organizationInfo of organizationids) {
      req.query.organizationid = organizationInfo.dataValues.organizationid
      const organization = await global.api.administrator.organizations.Organization.get(req)
      items.push(organization)
    }
    return items
  }
}

Test source (view on github)

/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
const DashboardTestHelper = require('@layeredapps/dashboard/test-helper.js')

describe('/api/administrator/organizations/organizations', function () {
  const cachedResponses = {}
  const cachedOrganizations = []
  const accountOrganizations = []
  before(async () => {
    await DashboardTestHelper.setupBeforeEach()
    await TestHelper.setupBeforeEach()
    const administrator = await TestHelper.createOwner()
    for (let i = 0, len = global.pageSize + 1; i < len; i++) {
      global.userProfileFields = ['contact-email', 'full-name']
      const user = await TestHelper.createUser()
      global.userProfileFields = ['display-email', 'display-name']
      await TestHelper.createProfile(user, {
        'display-name': user.profile.fullName,
        'display-email': user.profile.contactEmail
      })
      await TestHelper.createOrganization(user, {
        email: user.profile.displayEmail,
        name: 'My organization',
        profileid: user.profile.profileid,
        pin: `7788${i}`
      })
      cachedOrganizations.unshift(user.organization.organizationid)
    }
    global.userProfileFields = ['contact-email', 'full-name']
    const user = await TestHelper.createUser()
    global.userProfileFields = ['display-email', 'display-name']
    await TestHelper.createProfile(user, {
      'display-name': user.profile.fullName,
      'display-email': user.profile.contactEmail
    })
    for (let i = 0, len = 3; i < len; i++) {
      await TestHelper.createOrganization(user, {
        email: user.profile.displayEmail,
        name: 'My organization 1',
        profileid: user.profile.profileid,
        pin: `1234${i}`
      })
      accountOrganizations.unshift(user.organization.organizationid)
      cachedOrganizations.unshift(user.organization.organizationid)
    }
    const req1 = TestHelper.createRequest('/api/administrator/organizations/organizations?offset=1')
    req1.account = administrator.account
    req1.session = administrator.session
    cachedResponses.offset = await req1.get()
    const req2 = TestHelper.createRequest('/api/administrator/organizations/organizations?limit=1')
    req2.account = administrator.account
    req2.session = administrator.session
    cachedResponses.limit = await req2.get()
    const req3 = TestHelper.createRequest('/api/administrator/organizations/organizations?all=true')
    req3.account = administrator.account
    req3.session = administrator.session
    cachedResponses.all = await req3.get()
    const req4 = TestHelper.createRequest(`/api/administrator/organizations/organizations?accountid=${user.account.accountid}&all=true`)
    req4.account = administrator.account
    req4.session = administrator.session
    cachedResponses.accountid = await req4.get()
    const req5 = TestHelper.createRequest('/api/administrator/organizations/organizations')
    req5.account = administrator.account
    req5.session = administrator.session
    req5.filename = __filename
    req5.saveResponse = true
    cachedResponses.returns = await req5.get()
    global.pageSize = 3
    cachedResponses.pageSize = await req5.get()
  })
  describe('receives', () => {
    it('optional querystring offset (integer)', async () => {
      const offset = 1
      const organizationsNow = cachedResponses.offset
      for (let i = 0, len = global.pageSize; i < len; i++) {
        assert.strictEqual(organizationsNow[i].organizationid, cachedOrganizations[offset + i])
      }
    })

    it('optional querystring limit (integer)', async () => {
      const limit = 1
      const organizationsNow = cachedResponses.limit
      assert.strictEqual(organizationsNow.length, limit)
    })

    it('optional querystring all (boolean)', async () => {
      const organizationsNow = cachedResponses.all
      assert.strictEqual(organizationsNow.length, cachedOrganizations.length)
    })

    it('optional querystring accountid (string)', async () => {
      const organizationsNow = cachedResponses.accountid
      assert.strictEqual(organizationsNow.length, accountOrganizations.length)
    })
  })

  describe('returns', () => {
    it('array', async () => {
      const organizationsNow = cachedResponses.returns
      assert.strictEqual(organizationsNow.length, global.pageSize)
    })
  })

  describe('configuration', () => {
    it('environment PAGE_SIZE', async () => {
      global.pageSize = 3
      const organizationsNow = cachedResponses.pageSize
      assert.strictEqual(organizationsNow.length, global.pageSize)
    })
  })
})