@contentstack/management
Version:
The Content Management API is used to manage the content of your Contentstack account
70 lines (67 loc) • 2.53 kB
JavaScript
import cloneDeep from 'lodash/cloneDeep';
import { create, deleteEntity, fetchAll } from '../../../entity';
export function TeamUsers(http, data) {
if (data && data.userId) {
Object.assign(this, cloneDeep(data));
var _urlPath = "/organizations/".concat(this.organizationUid, "/teams/").concat(this.teamUid, "/users/").concat(data.userId);
if (this.organizationUid) this.urlPath = _urlPath;
/**
* @description The Remove teamUser call is used to remove an existing user of that team.
* @memberof TeamUsers
* @func remove
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').remove()
* .then((response) => console.log(response))
*
*/
this.remove = deleteEntity(http);
} else {
this.urlPath = "/organizations/".concat(data.organizationUid, "/teams/").concat(data.teamUid, "/users");
/**
* @description The Add teamUser call is used to add an user the team.
* @memberof TeamUsers
* @func add
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const usersMail = {
* emails: ['emailId1','emailId2' ]
* }
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').add(usersMail)
* .then((response) => console.log(response))
*
*/
this.add = create({
http: http
});
/**
* @description The Query on teamUser will allow to fetch details of all teamUsers.
* @memberof TeamUsers
* @func query
* @returns {Promise<TeamUsers.TeamUsers>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const usersMail = {
* emails: ['emailId1','emailId2' ]}
* client.organization('organizationUid').teams('teamUid').teamUsers('userId').query().find()
* .then((response) => console.log(response))
*
*/
this.fetchAll = fetchAll(http, UsersCollection);
}
}
export function UsersCollection(http, data) {
var obj = cloneDeep(data.users) || [];
var usersCollection = obj.map(function (userId) {
return new TeamUsers(http, {
userId: userId
});
});
return usersCollection;
}