@contentstack/management
Version:
The Content Management API is used to manage the content of your Contentstack account
80 lines (76 loc) • 2.99 kB
JavaScript
;
var _interopRequireDefault3 = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireDefault2 = _interopRequireDefault3(require("@babel/runtime/helpers/interopRequireDefault"));
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.TeamUsers = TeamUsers;
exports.UsersCollection = UsersCollection;
var _cloneDeep = require("lodash/cloneDeep");
var _cloneDeep2 = (0, _interopRequireDefault2["default"])(_cloneDeep);
var _entity = require("../../../entity");
function TeamUsers(http, data) {
if (data && data.userId) {
Object.assign(this, (0, _cloneDeep2["default"])(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 = (0, _entity.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 = (0, _entity.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 = (0, _entity.fetchAll)(http, UsersCollection);
}
}
function UsersCollection(http, data) {
var obj = (0, _cloneDeep2["default"])(data.users) || [];
var usersCollection = obj.map(function (userId) {
return new TeamUsers(http, {
userId: userId
});
});
return usersCollection;
}