Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 20 additions & 13 deletions src/actions/organization/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,17 +62,20 @@ async function createOrganization(organizationName, active, lock) {
* @apiParam (Payload) {String} members.lastName - member last name.
* @apiParam (Payload) {String[]} members.permissions - member permission list.
*
* @apiSuccess (Response) {String} id - organization id.
* @apiSuccess (Response) {String} name - organization name.
* @apiSuccess (Response) {Boolean} active - organization state.
* @apiSuccess (Response) {Object[]} members - organization members.
* @apiSuccess (Response) {String} members.username - member email.
* @apiSuccess (Response) {String} members.firstName - member first name.
* @apiSuccess (Response) {String} members.lastName - member last name.
* @apiSuccess (Response) {Date} members.invited - member invite date.
* @apiSuccess (Response) {Date} members.accepted - member accept invite date.
* @apiSuccess (Response) {String[]} members.permissions - member permission list.
* @apiSuccess (Response) {Object} metadata - organization metadata
* @apiSuccess (Response) {String} meta.invites - organization invites list.
* @apiSuccess (Response) {String} data.id - organization id.
* @apiSuccess (Response) {String} data.type - response type.
* @apiSuccess (Response) {String} data.attributes.id - organization id.
* @apiSuccess (Response) {String} data.attributes.name - organization name.
* @apiSuccess (Response) {Boolean} data.attributes.active - organization state.
* @apiSuccess (Response) {Object[]} data.attributes.members - organization members.
* @apiSuccess (Response) {String} data.attributes.members.username - member email.
* @apiSuccess (Response) {String} data.attributes.members.firstName - member first name.
* @apiSuccess (Response) {String} data.attributes.members.lastName - member last name.
* @apiSuccess (Response) {Date} data.attributes.members.invited - member invite date.
* @apiSuccess (Response) {Date} data.attributes.members.accepted - member accept invite date.
* @apiSuccess (Response) {String[]} data.attributes.members.permissions - member permission list.
* @apiSuccess (Response) {Object} data.attributes.metadata - organization metadata
*/
async function createOrganizationAction({ params, locals }) {
const service = this;
Expand All @@ -97,10 +100,14 @@ async function createOrganizationAction({ params, locals }) {
members,
});

const data = await getOrganizationMetadataAndMembers.call(this, organizationId);
const organization = await getOrganizationMetadataAndMembers.call(this, organizationId);

return {
data,
data: {
id: organizationId,
type: 'organization',
attributes: organization,
},
meta: {
invites,
},
Expand Down
34 changes: 21 additions & 13 deletions src/actions/organization/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,30 @@ const { getOrganizationMetadataAndMembers, checkOrganizationExists } = require('
*
* @apiParam (Payload) {String} organizationId - organization id.
*
* @apiSuccess (Response) {String} id - organization id.
* @apiSuccess (Response) {String} name - organization name.
* @apiSuccess (Response) {Boolean} active - organization state.
* @apiSuccess (Response) {Object[]} members - organization members.
* @apiSuccess (Response) {String} members.username - member email.
* @apiSuccess (Response) {String} members.firstName - member first name.
* @apiSuccess (Response) {String} members.lastName - member last name.
* @apiSuccess (Response) {Date} members.invited - member invite date.
* @apiSuccess (Response) {Date} members.accepted - member accept invite date.
* @apiSuccess (Response) {String[]} members.permissions - member permission list.
* @apiSuccess (Response) {Object} metadata - organization metadata
* @apiSuccess (Response) {String} data.id - organization id.
* @apiSuccess (Response) {String} data.type - response type.
* @apiSuccess (Response) {String} data.attributes.id - organization id.
* @apiSuccess (Response) {String} data.attributes.name - organization name.
* @apiSuccess (Response) {Boolean} data.attributes.active - organization state.
* @apiSuccess (Response) {Object[]} data.attributes.members - organization members.
* @apiSuccess (Response) {String} data.attributes.members.username - member email.
* @apiSuccess (Response) {String} data.attributes.members.firstName - member first name.
* @apiSuccess (Response) {String} data.attributes.members.lastName - member last name.
* @apiSuccess (Response) {Date} data.attributes.members.invited - member invite date.
* @apiSuccess (Response) {Date} data.attributes.members.accepted - member accept invite date.
* @apiSuccess (Response) {String[]} data.attributes.members.permissions - member permission list.
* @apiSuccess (Response) {Object} data.attributes.metadata - organization metadata
*/
async function getOrganization({ params }) {
const { organizationId } = params;
const data = await getOrganizationMetadataAndMembers.call(this, organizationId);
return { data };
const organization = await getOrganizationMetadataAndMembers.call(this, organizationId);
return {
data: {
id: organizationId,
type: 'organization',
attributes: organization,
},
};
}

getOrganization.allowed = checkOrganizationExists;
Expand Down
7 changes: 5 additions & 2 deletions src/actions/organization/getMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ const { getOrganizationMetadata, checkOrganizationExists } = require('../../util
*
* @apiParam (Payload) {String} organizationId - organization id.
*
* @apiSuccess (Response) {Object} metadata - organization metadata
* @apiSuccess (Response) {Object} data.id - organization id
* @apiSuccess (Response) {String} data.type - response type.
* @apiSuccess (Response) {Object} data.attributes.metadata - organization metadata
*/
async function organizationMetadata({ params }) {
const { organizationId } = params;
Expand All @@ -18,7 +20,8 @@ async function organizationMetadata({ params }) {
return {
data: {
id: organizationId,
metadata,
type: 'organizationMetadata',
attributes: metadata,
},
};
}
Expand Down
6 changes: 5 additions & 1 deletion src/actions/organization/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ async function getOrganizationsList({ params }) {
});

return {
data: organizations,
data: organizations.map(organization => ({
id: organization.id,
type: 'organization',
attributes: organization,
})),
meta: {
cursor: offset + limit,
page: Math.floor(offset / limit) + 1,
Expand Down
12 changes: 11 additions & 1 deletion src/actions/organization/members/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,17 @@ async function organizationMembersList({ params }) {
const { organizationId } = params;

const members = await getOrganizationMembers.call(this, organizationId);
return { data: { id: organizationId, members } };
return {
data: {
id: organizationId,
type: 'organizationMembers',
attributes: members.map(member => ({
id: member.username,
type: 'organizationMember',
attributes: member,
})),
},
};
}

organizationMembersList.allowed = checkOrganizationExists;
Expand Down
3 changes: 2 additions & 1 deletion src/actions/organization/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ async function updateOrganizationState({ params }) {
return {
data: {
id: organizationId,
active,
type: 'organizationState',
attributes: { active },
},
};
}
Expand Down
3 changes: 2 additions & 1 deletion src/actions/organization/updateMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ async function updateOrganizationMetadata({ params }) {
return {
data: {
id: organizationId,
metadata: data,
type: 'organizationMetadata',
attributes: data,
},
};
}
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/organization.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ exports.createOrganization = async function (customOpts = {}, totalUsers = 1) {
.then(inspectPromise(true));

this.organization = {
...organization.data,
...organization.data.attributes,
...organization.meta,
};
return this.organization;
Expand Down
2 changes: 1 addition & 1 deletion test/suites/organization/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('#create organization', function registerSuite() {
.reflect()
.then(inspectPromise(true))
.then((response) => {
const createdOrganization = response.data;
const createdOrganization = response.data.attributes;
assert(createdOrganization.name === params.name);
assert(createdOrganization.metadata.description === params.metadata.description);
assert(createdOrganization.members.length === 2);
Expand Down
2 changes: 1 addition & 1 deletion test/suites/organization/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ describe('#get organization', function registerSuite() {
.reflect()
.then(inspectPromise(true))
.then((response) => {
assert.deepEqual(response.data, organization);
assert.deepEqual(response.data.attributes, organization);
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/suites/organization/getMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ describe('#organization members metadata', function registerSuite() {
.reflect()
.then(inspectPromise(true))
.then((response) => {
assert.ok(response.data.metadata);
assert.deepEqual(response.data.metadata, this.organization.metadata);
assert.ok(response.data.attributes);
assert.deepEqual(response.data.attributes, this.organization.metadata);
});
});

Expand Down
10 changes: 6 additions & 4 deletions test/suites/organization/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ describe('#organizations list', function registerSuite() {
assert.equal(meta.pages, organizationsLength / opts.limit);
data.forEach((organization) => {
expect(organization).to.have.ownProperty('id');
expect(organization).to.have.ownProperty('metadata');
expect(organization).to.have.ownProperty('name');
expect(organization).to.have.ownProperty('active');
expect(organization).to.have.ownProperty('type');
expect(organization.attributes).to.have.ownProperty('id');
expect(organization.attributes).to.have.ownProperty('name');
expect(organization.attributes).to.have.ownProperty('active');
expect(organization.attributes).to.have.ownProperty('metadata');
});
});
});
Expand Down Expand Up @@ -69,7 +71,7 @@ describe('#organizations list', function registerSuite() {
assert.equal(meta.cursor, 1);
assert.equal(meta.page, 1);
assert.equal(meta.pages, 1);
assert.deepEqual(data[0], organization);
assert.deepEqual(data[0].attributes, organization);
});
});
});
4 changes: 2 additions & 2 deletions test/suites/organization/members/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ describe('#organization members list', function registerSuite() {
.reflect()
.then(inspectPromise(true))
.then((response) => {
assert.ok(response.data.members);
assert.equal(response.data.members.length, 5);
assert.ok(response.data.attributes);
assert.equal(response.data.attributes.length, 5);
});
});

Expand Down
2 changes: 1 addition & 1 deletion test/suites/organization/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('#switch state organization', function registerSuite() {
.reflect()
.then(inspectPromise(true))
.then((response) => {
assert.deepEqual({ id: this.organization.id, active: true }, response.data);
assert(response.data.attributes.active);
});
});

Expand Down
4 changes: 2 additions & 2 deletions test/suites/organization/updateMetadata.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ describe('#update metadata organization', function registerSuite() {
.reflect()
.then(inspectPromise(true))
.then((createdOrganization) => {
assert(createdOrganization.data.metadata.description === undefined);
assert(createdOrganization.data.metadata.address === 'test');
assert(createdOrganization.data.attributes.description === undefined);
assert(createdOrganization.data.attributes.address === 'test');
});
});

Expand Down