UNPKG

contentful-management

Version:
60 lines (57 loc) 1.74 kB
import { toPlainObject, freezeSys } from 'contentful-sdk-core'; import copy from 'fast-copy'; import { wrapCollection } from '../common-utils.mjs'; import enhanceWithMethods from '../enhance-with-methods.mjs'; /** * @internal */ function createTaskApi(makeRequest) { const getParams = (task) => { const parentEntity = task.sys.parentEntity; return { spaceId: task.sys.space.sys.id, environmentId: task.sys.environment.sys.id, parentEntityType: parentEntity.sys.linkType, parentEntityId: parentEntity.sys.id, taskId: task.sys.id, }; }; return { update: function () { const raw = this.toPlainObject(); return makeRequest({ entityType: 'Task', action: 'update', params: getParams(raw), payload: raw, }).then((data) => wrapTask(makeRequest, data)); }, delete: function () { const raw = this.toPlainObject(); return makeRequest({ entityType: 'Task', action: 'delete', params: { ...getParams(raw), version: raw.sys.version, }, }).then(() => { // noop }); }, }; } /** * @internal */ function wrapTask(makeRequest, data) { const task = toPlainObject(copy(data)); const taskWithMethods = enhanceWithMethods(task, createTaskApi(makeRequest)); return freezeSys(taskWithMethods); } /** * @internal */ const wrapTaskCollection = wrapCollection(wrapTask); export { wrapTask, wrapTaskCollection }; //# sourceMappingURL=task.mjs.map