Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return async (context) => {
// Throw if the hook is being called from an unexpected location.
checkContext(context, null, ['find', 'get', 'create', 'update', 'patch', 'remove']);
// Get the authenticated user.
// eslint-disable-next-line no-unused-vars
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;
return async (context) => {
// Throw if the hook is being called from an unexpected location.
checkContext(context, null, ['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;
newProps: { mongoose: { /*...*/ } },
hooksToDisable: 'populate'
})(context1);
// $ExpectType void
callingParamsDefaults(['abc', 'def'], {
someData: {}
});
// $ExpectType void
checkContext(context1, 'before', ['update', 'patch'], 'hookName');
// $ExpectType void
checkContext(context1, null, ['update', 'patch']);
// $ExpectType void
checkContext(context1, 'before', null, 'hookName');
// $ExpectType void
checkContext(context1, 'before');
// $ExpectType void
checkContextIf(context1, 'before', ['update', 'patch'], 'hookName');
// $ExpectType Hook>
combine(hook1, hook2, hook3);
// $ExpectType Hook>
debug('label', 'abc.def', 'ghi.jkl');
// $ExpectType Hook>
dePopulate();
// $ExpectType Hook>
disablePagination();
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.
// eslint-disable-next-line no-unused-vars
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;
// $ExpectType Params
callingParams({
query: { id: { $in: [1, 2, 3] } },
propNames: ['customProp'],
newProps: { mongoose: { /*...*/ } },
hooksToDisable: 'populate'
})(context1);
// $ExpectType void
callingParamsDefaults(['abc', 'def'], {
someData: {}
});
// $ExpectType void
checkContext(context1, 'before', ['update', 'patch'], 'hookName');
// $ExpectType void
checkContext(context1, null, ['update', 'patch']);
// $ExpectType void
checkContext(context1, 'before', null, 'hookName');
// $ExpectType void
checkContext(context1, 'before');
// $ExpectType void
checkContextIf(context1, 'before', ['update', 'patch'], 'hookName');
// $ExpectType Hook>
combine(hook1, hook2, hook3);
// $ExpectType Hook>
debug('label', 'abc.def', 'ghi.jkl');
// $ExpectType Hook>
dePopulate();
cache(new Map(), 'a', { clone: x => x });
// $ExpectType Params
callingParams({
query: { id: { $in: [1, 2, 3] } },
propNames: ['customProp'],
newProps: { mongoose: { /*...*/ } },
hooksToDisable: 'populate'
})(context1);
// $ExpectType void
callingParamsDefaults(['abc', 'def'], {
someData: {}
});
// $ExpectType void
checkContext(context1, 'before', ['update', 'patch'], 'hookName');
// $ExpectType void
checkContext(context1, null, ['update', 'patch']);
// $ExpectType void
checkContext(context1, 'before', null, 'hookName');
// $ExpectType void
checkContext(context1, 'before');
// $ExpectType void
checkContextIf(context1, 'before', ['update', 'patch'], 'hookName');
// $ExpectType Hook>
combine(hook1, hook2, hook3);
// $ExpectType Hook>
debug('label', 'abc.def', 'ghi.jkl');
return hook => {
checkContext(hook, 'after');
// Retrieve the items from the hook
let users = getItems(hook);
if (!users) return;
const isArray = Array.isArray(users);
users = (isArray ? users : [users]);
users.forEach(user => {
if (!('isVerified' in user) && hook.method === 'create') {
/* eslint-disable no-console */
console.warn('Property isVerified not found in user properties. (removeVerification)');
console.warn('Have you added authManagement\'s properties to your model? (Refer to README.md)');
console.warn('Have you added the addVerification hook on users::create?');
/* eslint-enable */
}
if (hook.params.provider && user) { // noop if initiated by server
return context => {
checkContext(context, 'after', null, 'clearDataLoaderKey');
if (mutatingMethods.indexOf(context.method) === -1) return; // ignore any custom methods
if (typeof getDataLoaderKey !== 'function') {
const fieldName = getDataLoaderKey || context.service.id;
getDataLoaderKey = record => record[fieldName];
}
dataLoaderNames = Array.isArray(dataLoaderNames) ? dataLoaderNames : [dataLoaderNames];
const persistedDataLoaders = context.service.persistedDataLoaders;
const records = extractAllItems(context.result);
records.forEach(record => {
const key = getDataLoaderKey(record);
const dataLoaderKey = typeof key === 'string' ? key : key.toString();
dataLoaderNames.forEach(name => {
return function(hook) {
checkContext(hook, 'after', [], 'onlyOneIfWasGET');
if(hook.params[property]) {
hook.result = hook.result[0]
}
}
};