import { CmsFieldTypePlugins , CmsModel } from "~/types" ; import get from "lodash/get" ; interface RenderGetFilterFields { ( params ) : string ; } export const renderGetFilterFields = ( { model , fieldTypePlugins } ) => { const fieldIds = model . fields . filter ( f => { return get ( fieldTypePlugins , `${ f . type }.isSearchable` ) ; } ) . map ( f => f . fieldId ) ; const filters = [ "id: ID" , "entryId: String" ] ; for ( let i = 0 ; i < fieldIds . length ; i ++ ) { const field = model . fields . find ( item => item . fieldId === fieldIds [ i ] ) ; const createGetFilters = get ( fieldTypePlugins , `${ field . type }.read.createGetFilters` ) ; if ( typeof createGetFilters === "function" ) { filters . push ( createGetFilters ( { model , field } ) ) ; } } return filters . filter ( Boolean ) . join ( "\n" ) ; } ;