throwIfIsMulti
Source Code | DocumentationSee also: predicates/isMulti
Throws a BadRequest error when the current operation is a multi operation (array data on create, or id === null on patch/remove). Useful to prevent bulk operations on services that should only handle single items.
ts
import { throwIfIsMulti } from 'feathers-utils/hooks';Example
ts
import { throwIfIsMulti } from 'feathers-utils/hooks'
app.service('users').hooks({
before: { all: [throwIfIsMulti()] }
})Type declaration
Show Type Declarations
ts
export type ThrowIfIsMultiOptions = {
/**
* A predicate function to filter the contexts that should be checked for multi operations.
* If provided, only contexts that pass this predicate will be checked for multi operations.
*/
filter?: PredicateFn
/**
* Customize the error that is thrown if the context is multi and the service does not allow it.
* If not provided, throws a `BadRequest` error.
*/
error?: (context: HookContext) => FeathersError
}
/**
* Throws a `BadRequest` error when the current operation is a multi operation
* (array data on `create`, or `id === null` on `patch`/`remove`).
* Useful to prevent bulk operations on services that should only handle single items.
*
* @example
* ```ts
*
*
* app.service('users').hooks({
* before: { all: [throwIfIsMulti()] }
* })
* ```
*
* @see https://utils.feathersjs.com/hooks/throw-if-is-multi.html
*/
export declare const throwIfIsMulti: <H extends HookContext = HookContext>(
options?: ThrowIfIsMultiOptions,
) => (context: H, next?: HookContext) => Promise<any>| Argument | Type | Description |
|---|---|---|
| options | ThrowIfIsMultiOptions |
| type | methods | multi |
|---|---|---|
| before, after, around | create, update, patch | yes |
