/api/administrator/organizations/invitation (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.organizations.Invitation.get(req)Returns object
{
"invitationid": "invt_48ddc3f178816e6c",
"organizationid": "orgn_e5468c580fa46cd3",
"accountid": "acct_448bfbec147ed134",
"object": "invitation",
"appid": "tests_1656039695",
"multi": true,
"acceptedAt": null,
"terminatedAt": null,
"createdAt": "2022-06-24T03:01:35.163Z",
"updatedAt": "2022-06-24T03:01:35.163Z"
}
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-invitationid | missing querystring invitationid |
invalid querystring invitationid |
NodeJS source (view on github)
const dashboard = require('@layeredapps/dashboard')
const organizations = require('../../../../../index.js')
module.exports = {
get: async (req) => {
if (!req.query || !req.query.invitationid) {
throw new Error('invalid-invitationid')
}
let invitation = await dashboard.StorageCache.get(req.query.invitationid)
if (!invitation) {
const invitationInfo = await organizations.Storage.Invitation.findOne({
where: {
invitationid: req.query.invitationid,
appid: req.appid || global.appid
}
})
if (!invitationInfo) {
throw new Error('invalid-invitationid')
}
invitation = {}
for (const field of invitationInfo._options.attributes) {
invitation[field] = invitationInfo.get(field)
}
await dashboard.StorageCache.set(req.query.invitationid, invitation)
}
req.query.organizationid = invitation.organizationid
const organization = await global.api.administrator.organizations.Organization.get(req)
if (!organization) {
throw new Error('invalid-organizationid')
}
delete (invitation.secretCode)
return invitation
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
describe('/api/administrator/organizations/invitation', () => {
describe('exceptions', () => {
describe('invalid-invitationid', () => {
it('missing querystring invitationid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/organizations/invitation')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-invitationid')
})
it('invalid querystring invitationid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/organizations/invitation?invitationid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-invitationid')
})
})
})
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.fullName,
'display-email': owner.profile.contactEmail
})
await TestHelper.createOrganization(owner, {
email: owner.profile.displayEmail,
name: 'My organization',
profileid: owner.profile.profileid,
pin: '12345'
})
await TestHelper.createInvitation(owner)
const req = TestHelper.createRequest(`/api/administrator/organizations/invitation?invitationid=${owner.invitation.invitationid}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const invitation = await req.get()
assert.strictEqual(invitation.object, 'invitation')
})
})
})