contentful-management
Version:
Client for Contentful's Content Management API
48 lines (46 loc) • 1.53 kB
JavaScript
/**
* @internal
* @param id - unique ID of the field
* @param key - the attribute on the field to change
* @param value - the value to set the attribute to
*/
const findAndUpdateField = function (contentType, fieldId, omitOrDelete) {
const field = contentType.fields.find((field) => field.id === fieldId);
if (!field) {
return Promise.reject(new Error(`Tried to omitAndDeleteField on a nonexistent field, ${fieldId}, on the content type ${contentType.name}.`));
}
field[omitOrDelete] = true;
return Promise.resolve(contentType);
};
const omitAndDeleteField = (makeRequest, { fieldId, ...params }, contentType) => {
return findAndUpdateField(contentType, fieldId, 'omitted')
.then((newContentType) => {
return makeRequest({
entityType: 'ContentType',
action: 'update',
params,
payload: newContentType,
});
})
.then((newContentType) => {
return makeRequest({
entityType: 'ContentType',
action: 'publish',
params,
payload: newContentType,
});
})
.then((newContentType) => {
return findAndUpdateField(newContentType, fieldId, 'deleted');
})
.then((newContentType) => {
return makeRequest({
entityType: 'ContentType',
action: 'update',
params,
payload: newContentType,
});
});
};
export { omitAndDeleteField };
//# sourceMappingURL=content-type.js.map