checkRequired
Source Code | DocumentationValidates that the specified fields exist on context.data and are not falsy. Numeric 0 and boolean false are treated as valid values. Throws a BadRequest error if any required field is missing or null.
ts
import { checkRequired } from 'feathers-utils/hooks';Example
ts
import { checkRequired } from 'feathers-utils/hooks'
app.service('users').hooks({
before: { create: [checkRequired(['email', 'password'])] }
})Type declaration
Show Type Declarations
ts
/**
* Validates that the specified fields exist on `context.data` and are not falsy.
* Numeric `0` and boolean `false` are treated as valid values.
* Throws a `BadRequest` error if any required field is missing or null.
*
* @example
* ```ts
*
*
* app.service('users').hooks({
* before: { create: [checkRequired(['email', 'password'])] }
* })
* ```
*
* @see https://utils.feathersjs.com/hooks/check-required.html
*/
export declare function checkRequired<H extends HookContext = HookContext>(
fieldNames: MaybeArray<string>,
): (context: H, next?: NextFunction) => any| Argument | Type | Description |
|---|---|---|
| fieldNames | MaybeArray<string> |
| type | methods | multi |
|---|---|---|
| before, around | create, update, patch | yes |
