Skip to content

stashBefore

hooks
Source Code | Documentation

Stashes the current value of a record into params.before prior to mutation. Performs a get (single item) or find (multi) call to retrieve the existing state. Useful in update, patch, or remove hooks when you need the original data for comparison.

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

Example

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

app.service('users').hooks({
  before: { patch: [stashBefore()] }
})
// Access via: context.params.before

Type declaration

Show Type Declarations
ts
/**
 * Stashes the current value of a record into `params.before` prior to mutation.
 * Performs a `get` (single item) or `find` (multi) call to retrieve the existing state.
 * Useful in `update`, `patch`, or `remove` hooks when you need the original data for comparison.
 *
 * @example
 * ```ts
 *
 *
 * app.service('users').hooks({
 *   before: { patch: [stashBefore()] }
 * })
 * // Access via: context.params.before
 * ```
 *
 * @see https://utils.feathersjs.com/hooks/stash-before.html
 */
export declare function stashBefore<H extends HookContext = HookContext>(
  fieldName?: string,
): (context: H, next?: NextFunction) => Promise<any>
ArgumentTypeDescription
fieldNamestring
typemethodsmulti
before, aroundget, update, patch, removeyes

Released under the MIT License.