contentful-management
Version:
Client for Contentful's Content Management API
52 lines (49 loc) • 1.49 kB
JavaScript
import copy from 'fast-copy';
import { toPlainObject, freezeSys } from 'contentful-sdk-core';
import enhanceWithMethods from '../enhance-with-methods.js';
import { wrapCollection } from '../common-utils.js';
/**
* @internal
*/
function createTeamApi(makeRequest) {
const getParams = (data) => ({
teamId: data.sys.id,
organizationId: data.sys.organization.sys.id,
});
return {
update: function update() {
const raw = this.toPlainObject();
return makeRequest({
entityType: 'Team',
action: 'update',
params: getParams(raw),
payload: raw,
}).then((data) => wrapTeam(makeRequest, data));
},
delete: function del() {
const raw = this.toPlainObject();
return makeRequest({
entityType: 'Team',
action: 'delete',
params: getParams(raw),
});
},
};
}
/**
* @internal
* @param makeRequest - function to make requests via an adapter
* @param data - Raw team data
* @returns Wrapped team data
*/
function wrapTeam(makeRequest, data) {
const team = toPlainObject(copy(data));
const teamWithMethods = enhanceWithMethods(team, createTeamApi(makeRequest));
return freezeSys(teamWithMethods);
}
/**
* @internal
*/
const wrapTeamCollection = wrapCollection(wrapTeam);
export { wrapTeam, wrapTeamCollection };
//# sourceMappingURL=team.js.map