// Use this hook to manipulate incoming or outgoing data. // For more information on hooks see: http://docs.feathersjs.com/api/hooks.html import { Hook } from '@feathersjs/feathers'; import { checkContext, getItems, replaceItems } from 'feathers-hooks-common'; // tslint:disable-next-line:no-unused-variable export default function (options: any = {}): Hook { // Return the actual hook. return async (context) => { // Throw if the hook is being called from an unexpected location. checkContext(context, 'after', ['find', 'get', 'create', 'update', 'patch', 'remove']); // Get the authenticated user. // tslint:disable-next-line:no-unused-variable const { user } = context.params!; // Get the record(s) from context.data (before), context.result.data or context.result (after). // getItems always returns an array to simplify your processing. const records = getItems(context); /* Modify records and/or context. */ // Place the modified records back in the context. replaceItems(context, records); // Best practice: hooks should always return the context. return context; }; } // Throw to reject the service call, or on an unrecoverable error. // tslint:disable-next-line:no-unused-variable function error(msg: string) { throw new Error(msg); }