/api/administrator/organizations/membership (GET)
Account information like email addresses is generated with faker-js it is not real user information.
await global.api.administrator.organizations.Membership.get(req)Returns object
{
"membershipid": "mmbr_6a0f16cd7e534acb",
"object": "membership",
"appid": "tests_1656039696",
"accountid": "acct_05f0ea441d3afdb8",
"organizationid": "orgn_4e63f4a8363c93f6",
"invitationid": "invt_913022a5d07d369c",
"profileid": "prof_04e317d858c337f4",
"createdAt": "2022-06-24T03:01:36.590Z",
"updatedAt": "2022-06-24T03:01:36.590Z",
"displayName": "Brent Kovacek",
"displayEmail": "Brent.Kovacek@gmail.com"
}
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-membershipid | missing querystring membershipid |
invalid querystring membershipid |
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.membershipid) {
throw new Error('invalid-membershipid')
}
let membership = await dashboard.StorageCache.get(req.query.membershipid)
if (!membership) {
const membershipInfo = await organizations.Storage.Membership.findOne({
where: {
membershipid: req.query.membershipid,
appid: req.appid || global.appid
}
})
if (!membershipInfo) {
throw new Error('invalid-membershipid')
}
membership = {}
for (const field of membershipInfo._options.attributes) {
membership[field] = membershipInfo.get(field)
}
await dashboard.StorageCache.set(req.query.membershipid, membership)
}
req.query.profileid = membership.profileid
const profile = await global.api.administrator.Profile.get(req)
const requireProfileFields = global.membershipProfileFields
for (const field of requireProfileFields) {
if (field === 'full-name') {
membership.fullName = profile.fullName
} else {
const displayName = global.profileFieldMap[field]
membership[displayName] = profile[displayName]
}
}
return membership
}
}
Test source (view on github)
/* eslint-env mocha */
const assert = require('assert')
const TestHelper = require('../../../../../test-helper.js')
describe('/api/administrator/organizations/membership', () => {
describe('exceptions', () => {
describe('invalid-membershipid', () => {
it('missing querystring membershipid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/organizations/membership')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-membershipid')
})
it('invalid querystring membershipid', async () => {
const administrator = await TestHelper.createOwner()
const req = TestHelper.createRequest('/api/administrator/organizations/membership?membershipid=invalid')
req.account = administrator.account
req.session = administrator.session
let errorMessage
try {
await req.get()
} catch (error) {
errorMessage = error.message
}
assert.strictEqual(errorMessage, 'invalid-membershipid')
})
})
})
describe('returns', () => {
it('object', async () => {
const administrator = await TestHelper.createOwner()
const owner = await TestHelper.createUser()
const user = 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.createProfile(user, {
'display-name': user.profile.fullName,
'display-email': user.profile.contactEmail
})
await TestHelper.createOrganization(owner, {
email: owner.profile.displayEmail,
name: 'My organization',
profileid: owner.profile.profileid,
pin: '12345'
})
await TestHelper.createInvitation(owner)
await TestHelper.acceptInvitation(user, owner)
const req = TestHelper.createRequest(`/api/administrator/organizations/membership?membershipid=${user.membership.membershipid}`)
req.account = administrator.account
req.session = administrator.session
req.filename = __filename
req.saveResponse = true
const membership = await req.get()
assert.strictEqual(membership.object, 'membership')
})
})
})