setField
The setField hook allows to set a field on the hook context based on the value of another field on the hook context.
ts
import { setField } from 'feathers-utils/hooks';Type declaration
ts
export interface SetFieldOptions {
as: string
from: string
/**
* If set to `true`, allows the field to be undefined.
* If the field is not available and this is `true`, the hook will not throw an error.
*
* If set to `false`, the hook will throw an error if the field is not available.
*
* @default false
*/
allowUndefined?: boolean
/**
* Customize the error that is thrown if the field is not available.
*
* If not provided, throws a `Forbidden` error with a message indicating the missing field.
*/
error?: (context: HookContext, from: string) => FeathersError
}
/**
* The `setField` hook allows to set a field on the hook context based on the value of another field on the hook context.
*
* @see https://utils.feathersjs.com/hooks/set-field.html
*/
export declare const setField: <H extends HookContext = HookContext>({
as,
from,
allowUndefined,
error,
}: SetFieldOptions) => (context: H, next?: NextFunction) => any| Argument | Type | Description |
|---|---|---|
| { as, from, allowUndefined = false, error, } | SetFieldOptions |
| type | methods | multi |
|---|---|---|
| before, after, around | all | yes |
