@contentstack/management
Version:
The Content Management API is used to manage the content of your Contentstack account
203 lines (196 loc) • 7.38 kB
JavaScript
;
var _interopRequireDefault3 = require("@babel/runtime/helpers/interopRequireDefault");
var _interopRequireDefault2 = _interopRequireDefault3(require("@babel/runtime/helpers/interopRequireDefault"));
Object.defineProperty(exports, "__esModule", {
value: true
});
var _asyncToGenerator2 = require("@babel/runtime/helpers/asyncToGenerator");
var _asyncToGenerator3 = (0, _interopRequireDefault2["default"])(_asyncToGenerator2);
exports.Teams = Teams;
exports.TeamsCollection = TeamsCollection;
var _regenerator = require("@babel/runtime/regenerator");
var _regenerator2 = (0, _interopRequireDefault2["default"])(_regenerator);
var _cloneDeep = require("lodash/cloneDeep");
var _cloneDeep2 = (0, _interopRequireDefault2["default"])(_cloneDeep);
var _entity = require("../../entity");
var _teamUsers = require("./teamUsers");
var _stackRoleMappings = require("./stackRoleMappings");
var _contentstackError = require("../../core/contentstackError");
var _contentstackError2 = (0, _interopRequireDefault2["default"])(_contentstackError);
function Teams(http, data) {
var _this = this;
this.organizationUid = data.organizationUid;
this.urlPath = "/organizations/".concat(this.organizationUid, "/teams");
if (data && data.uid) {
Object.assign(this, (0, _cloneDeep2["default"])(data));
this.urlPath = "/organizations/".concat(this.organizationUid, "/teams/").concat(this.uid);
/**
* @description The update call on team will allow to update details of team.
* @memberof Teams
* @func update
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const updateData = {
* name: 'updatedname',
* users: [
* {
* email: 'abc@abc.com'
* }
* ],
* organizationRole: 'blt09e5dfced326aaea',
* stackRoleMapping: []
* }
* client.organization(s'organizationUid').teams('teamUid').update(updateData)
* .then((response) => console.log(response))
*
*/
this.update = /*#__PURE__*/function () {
var _ref = (0, _asyncToGenerator3["default"])(/*#__PURE__*/_regenerator2["default"].mark(function _callee(updateData) {
var response, _t;
return _regenerator2["default"].wrap(function (_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_context.next = 1;
return http.put(_this.urlPath, updateData);
case 1:
response = _context.sent;
if (!response.data) {
_context.next = 2;
break;
}
return _context.abrupt("return", response.data);
case 2:
_context.next = 4;
break;
case 3:
_context.prev = 3;
_t = _context["catch"](0);
throw (0, _contentstackError2["default"])(_t);
case 4:
case "end":
return _context.stop();
}
}, _callee, null, [[0, 3]]);
}));
return function (_x) {
return _ref.apply(this, arguments);
};
}();
/**
* @description The delete call on team will delete the existing team.
* @memberof Teams
* @func delete
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').delete()
* .then((response) => console.log(response))
*
*/
this["delete"] = (0, _entity.deleteEntity)(http);
/**
* @description The fetch call on team will delete the existing team.
* @memberof Teams
* @func fetch
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').fetch()
* .then((response) => console.log(response))
*
*/
this.fetch = (0, _entity.fetch)(http, 'team');
/**
* @description The users call on team will get users details.
* @memberof Teams
* @func users
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').teamUsers().fetchAll()
* .then((response) => console.log(response))
*
*/
this.teamUsers = function () {
var userId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
data.organizationUid = _this.organizationUid;
data.teamUid = _this.uid;
if (userId) {
data.userId = userId;
}
return new _teamUsers.TeamUsers(http, data);
};
/**
* @description The stackRoleMappings call on team will get the stack role Mapping.
* @memberof Teams
* @func users
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* client.organization('organizationUid').teams('teamUid').stackRoleMappings().fetchAll()
* .then((response) => console.log(response))
*
*/
this.stackRoleMappings = function () {
var stackApiKey = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
data.organizationUid = _this.organizationUid;
data.teamUid = _this.uid;
if (stackApiKey) {
data.stackApiKey = stackApiKey;
}
return new _stackRoleMappings.StackRoleMappings(http, data);
};
} else {
/**
* @description The fetch call on team will delete the existing team.
* @memberof Teams
* @func create
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
* const team = {
* name: 'name',
* organizationUid: 'organization_uid',
* users: [],
* stackRoleMapping: [],
* organizationRole: 'organizationRole'
* }
* client.organization('organizationUid').teams().create(team)
* .then((response) => console.log(response))
*
*/
this.create = (0, _entity.create)({
http: http
});
/**
* @description The fetchAll on team will allow to fetch details of all teams.
* @memberof Teams
* @func fetchAll
* @returns {Promise<Teams.Teams>} Response Object.
* @example
* import * as contentstack from '@contentstack/management'
* const client = contentstack.client()
*
* client.organization('organizationUid').teams().fetchAll()
* .then((response) => console.log(response))
*/
this.fetchAll = (0, _entity.fetchAll)(http, TeamsCollection, {
api_version: 1.1
});
}
}
function TeamsCollection(http, teamsData) {
var obj = (0, _cloneDeep2["default"])(teamsData.teams) || [];
var teamsCollection = obj.map(function (team) {
return new Teams(http, team);
});
return teamsCollection;
}