Skip to content

checkMulti

hooks
Source Code | Documentation

See also: predicates/isMulti

Checks if the multi option is enabled for the current method and throws a MethodNotAllowed error if multi operations are not permitted. Useful to guard against accidental bulk create, patch, or remove calls.

ts
  import { 
checkMulti
} from 'feathers-utils/hooks';

Example

ts
import { checkMulti } from 'feathers-utils/hooks'

app.service('users').hooks({
  before: { create: [checkMulti()] }
})

Type declaration

Show Type Declarations
ts
export type CheckMultiOptions = {
  /**
   * Customize the error that is thrown if the service does not allow multi operations.
   *
   * If not provided, throws a `MethodNotAllowed` error with a message indicating the operation.
   */
  error?: (context: HookContext) => FeathersError
}
/**
 * Checks if the `multi` option is enabled for the current method and throws a
 * `MethodNotAllowed` error if multi operations are not permitted.
 * Useful to guard against accidental bulk `create`, `patch`, or `remove` calls.
 *
 * @example
 * ```ts
 *
 *
 * app.service('users').hooks({
 *   before: { create: [checkMulti()] }
 * })
 * ```
 *
 * @see https://utils.feathersjs.com/hooks/check-multi.html
 */
export declare function checkMulti<H extends HookContext = HookContext>(
  options?: CheckMultiOptions,
): (context: H, next?: NextFunction) => any
ArgumentTypeDescription
optionsCheckMultiOptions
typemethodsmulti
before, aroundcreate, patch, removeyes

Released under the MIT License.