UNPKG

@contentstack/management

Version:

The Content Management API is used to manage the content of your Contentstack account

68 lines (65 loc) 2.44 kB
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<Object>} 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 a user to the team. * @memberof TeamUsers * @func add * @returns {Promise<Object>} Response Object. * @example * import * as contentstack from '@contentstack/management' * const client = contentstack.client() * const usersMail = { * emails: ['emailId1','emailId2' ] * } * client.organization('organizationUid').teams('teamUid').teamUsers().add(usersMail) * .then((response) => console.log(response)) * */ this.add = create({ http: http }); /** * @description The fetchAll call allows you to fetch details of all team users. * @memberof TeamUsers * @func fetchAll * @returns {Promise<ContentstackCollection>} Promise for ContentstackCollection instance. * @example * import * as contentstack from '@contentstack/management' * const client = contentstack.client() * client.organization('organizationUid').teams('teamUid').teamUsers().fetchAll() * .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; }