import { GetContentTypeParams , MakeRequest } from '../common-types' ; import { ContentTypeProps } from '../entities/content-type' ; type OmitOrDelete = 'omitted' | 'deleted' ; private param id param key param value 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 ) ; } ; export 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 findAndUpdateField ( newContentType , fieldId , 'deleted' ) ; } ) . then ( ( newContentType ) => { return makeRequest ( { entityType : 'ContentType' , action : 'update' , params , payload : newContentType , } ) ; } ) ; } ;