How to use the feathers-hooks-common.checkContext function in feathers-hooks-common

To help you get started, we’ve selected a few feathers-hooks-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github feathers-plus / generator-feathers-plus / test-expands / a-gens / js / test-hook-integ.test-expected / src1 / hooks / hook.app1.js View on Github external
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;
github feathers-plus / generator-feathers-plus / test-expands / ts-cumulative-2-hooks.test-expected / src1 / hooks / hook.nedb12.ts View on Github external
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;
github feathersjs-ecosystem / feathers-hooks-common / types / tests.ts View on Github external
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();
github feathers-plus / generator-feathers-plus / examples / js / 12-test-examples / feathers-app / src / services / users / hooks / verify-email.js View on Github external
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;
github feathersjs-ecosystem / feathers-hooks-common / types / tests.ts View on Github external
// $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();
github feathersjs-ecosystem / feathers-hooks-common / types / tests.ts View on Github external
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');
github feathers-plus / feathers-authentication-management / src / hooks / remove-verification.js View on Github external
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
github feathers-plus / graphql / lib / run-time / feathers / hooks.js View on Github external
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 => {
github codingfriend1 / Feathers-Vue / server / hooks / only-one-if-was-get.js View on Github external
return function(hook) {
    checkContext(hook, 'after', [], 'onlyOneIfWasGET');
    if(hook.params[property]) {
      hook.result = hook.result[0]
    }
  }
};