/api/administrator/organizations/organization (GET)
await global.api.administrator.organizations.Organization.get(req) Located in Organizations module 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 organizationid | |
invalid-organizationid | unspecified querystring organizationid |
NodeJS source (edit on github)
If you see a problem with the source submit a pull request on Github.
const organizations = require('../../../../../index.js')
module.exports = {
get: async (req) => {
if (!req.query || !req.query.organizationid) {
throw new Error('invalid-organizationid')
}
let organization = await organizations.Storage.read(`${req.appid}/organization/${req.query.organizationid}`)
if (!organization) {
throw new Error('invalid-organizationid')
}
organization = JSON.parse(organization)
if (organization.object !== 'organization') {
throw new Error('invalid-organizationid')
}
return organization
}
}
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/organizations/organization', () => {
describe('exceptions', () => {
describe('invalid-organizationid', () => {
it('unspecified querystring organizationid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/organizations/organization')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-organizationid')
})
it('invalid querystring organizationid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/organizations/organization?organizationid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-organizationid')
})
})
})
describe('returns', () => {
it('object', async () => {
const administrator = await TestHelper.createOwner()
const owner = await TestHelper.createUser()
global.userProfileFields = ['display-name', 'display-email']
await TestHelper.createProfile(owner, {
'display-name': owner.profile.firstName,
'display-email': owner.profile.contactEmail
})
await TestHelper.createOrganization(owner, {
email: owner.profile.displayEmail,
name: 'My organization',
profileid: owner.profile.profileid
})
const req = TestHelper.createRequest(`/api/administrator/organizations/organization?organizationid=${owner.organization.organizationid}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const organization = await req.get()
assert.strictEqual(organization.object, 'organization')
})
})
})