lib/routing/buildRoutes.js
function getFilters(type, controller, action) {
  // User can set 'only' and 'except' rules on filters to be used on one
  // or many action methods.
  let useOptions = { only: true, except: false }

  // Only return action filter methods that apply.
  return _.filter(controller[`__${type}Filters`], filter => {
    // An action must be defined in each filter.
    if(!('action' in filter) || !filter.action)
      throw new Error(`No action defined in filter for [${controller.constructor.name}.${type}: ${JSON.stringify(filter)}].`)

    // Filter cannot contain both options.
    let containsBoth = _.every(_.keys(useOptions), o => o in filter)
    if(containsBoth)
      throw new Error(`${type[0].toUpperCase() + type.slice(1)} filter cannot have both \'only\' and \'except\' keys.`)

    let option = _.first(_.intersection(_.keys(useOptions), _.keys(filter)))
    // If no option is defined, use for all actions.
    if(!option)
      return true

    let useActions, use = useOptions[option]
    useActions = typeof (useActions = filter[option]) === 'string' ? [useActions] : useActions
    // Determine if filter can be used for this action.
    for(let ua of useActions)
      if(ua === action)
        return use

    return !use
  })
}
function getFilters(type, controller, action) {
  // User can set 'only' and 'except' rules on filters to be used on one
  // or many action methods.
  let useOptions = { only: true, except: false }

  // Only return action filter methods that apply.
  return _.filter(controller[`__${type}Filters`], filter => {
    // An action must be defined in each filter.
    if(!('action' in filter) || !filter.action)
      throw new Error(`No action defined in filter for [${controller.constructor.name}.${type}: ${JSON.stringify(filter)}].`)

    // Filter cannot contain both options.
    let containsBoth = _.every(_.keys(useOptions), o => o in filter)
    if(containsBoth)
      throw new Error(`${type[0].toUpperCase() + type.slice(1)} filter cannot have both \'only\' and \'except\' keys.`)

    let option = _.first(_.intersection(_.keys(useOptions), _.keys(filter)))
    // If no option is defined, use for all actions.
    if(!option)
      return true

    let useActions, use = useOptions[option]
    useActions = typeof (useActions = filter[option]) === 'string' ? [useActions] : useActions
    // Determine if filter can be used for this action.
    for(let ua of useActions)
      if(ua === action)
        return use

    return !use
  })
}
function getFilters ( type , controller , action ) { // User can set 'only' and 'except' rules on filters to be used on one // or many action methods. let useOptions = { only : true , except : false } // Only return action filter methods that apply. return _ . filter ( controller [ ` ${ type } ` ] , filter => { // An action must be defined in each filter. if ( ! ( 'action' in filter ) || ! filter . action ) throw new Error ( ` ${ controller . constructor . name } ${ type } ${ JSON . stringify ( filter ) } ` ) // Filter cannot contain both options. let containsBoth = _ . every ( _ . keys ( useOptions ) , o => o in filter ) if ( containsBoth ) throw new Error ( ` ${ type [ 0 ] . toUpperCase ( ) + type . slice ( 1 ) } \' \' \' \' ` ) let option = _ . first ( _ . intersection ( _ . keys ( useOptions ) , _ . keys ( filter ) ) ) // If no option is defined, use for all actions. if ( ! option ) return true let useActions , use = useOptions [ option ] useActions = typeof ( useActions = filter [ option ] ) === 'string' ? [ useActions ] : useActions // Determine if filter can be used for this action. for ( let ua of useActions ) if ( ua === action ) return use return ! use } ) }
Get list of filters based on the type name to be applied to a specific action.
Get list of filters based on the type name to be applied to a specific action .