How to use the feathers-hooks-common.when 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 feathersjs-ecosystem / feathers-hooks-common / types / tests.ts View on Github external
// $ExpectType Hook>
iffElse(asyncTrue, [hook1, hook2], [hook3, hook4]);

// $ExpectType IffHook
iff(syncTrue, hook1, hook2);
// $ExpectType IffHook
iff(asyncTrue, hook1, hook2);
// $ExpectType Hook>
iff(syncTrue, hook1, hook2).else(hook3, hook4);
// $ExpectType Hook>
iff(asyncTrue, hook1, hook2).else(hook3, hook4);

// $ExpectType IffHook
when(syncTrue, hook1, hook2);
// $ExpectType Hook>
when(syncTrue, hook1, hook2).else(hook3, hook4);

// $ExpectType Hook>
unless(asyncTrue, hook1, hook2);
// $ExpectType Hook>
unless(syncTrue, hook1, hook2);

// $ExpectType AsyncContextFunction
some(asyncFalse, asyncTrue, syncTrue);

// $ExpectType AsyncContextFunction
every(asyncTrue, syncTrue);

// $ExpectType AsyncContextFunction
isNot(asyncTrue);
// $ExpectType AsyncContextFunction
isNot(syncTrue);
github feathersjs-ecosystem / feathers-hooks-common / types / tests.ts View on Github external
// $ExpectType Hook>
iffElse(syncTrue, [hook1, hook2], [hook3, hook4]);
// $ExpectType Hook>
iffElse(asyncTrue, [hook1, hook2], [hook3, hook4]);

// $ExpectType IffHook
iff(syncTrue, hook1, hook2);
// $ExpectType IffHook
iff(asyncTrue, hook1, hook2);
// $ExpectType Hook>
iff(syncTrue, hook1, hook2).else(hook3, hook4);
// $ExpectType Hook>
iff(asyncTrue, hook1, hook2).else(hook3, hook4);

// $ExpectType IffHook
when(syncTrue, hook1, hook2);
// $ExpectType Hook>
when(syncTrue, hook1, hook2).else(hook3, hook4);

// $ExpectType Hook>
unless(asyncTrue, hook1, hook2);
// $ExpectType Hook>
unless(syncTrue, hook1, hook2);

// $ExpectType AsyncContextFunction
some(asyncFalse, asyncTrue, syncTrue);

// $ExpectType AsyncContextFunction
every(asyncTrue, syncTrue);

// $ExpectType AsyncContextFunction
isNot(asyncTrue);
github Human-Connection / API / server / services / users / users.hooks.js View on Github external
hook.data.isVerified = true;
          return hook;
        }
      ),
      when(isProvider('external'),
        restrictUserRole(),
        createAdmin()
      ),
      saveRemoteImages(['avatar', 'coverImg'])
    ],
    update: [
      ...restrict,
      hashPassword(),
      disableMultiItemChange(),
      lowerCase('email', 'username'),
      when(isProvider('external'),
        restrictUserRole()
      ),
      saveRemoteImages(['avatar', 'coverImg'])
    ],
    patch: [
      ...restrict,
      disableMultiItemChange(),
      lowerCase('email', 'username'),
      // Only set slug once
      when(
        hook => {
          return hook.params && hook.params.user && !hook.params.user.slug;
        },
        createSlug({ field: 'name' })
      ),
      when(isProvider('external'),
github Human-Connection / API / server / services / users / users.hooks.js View on Github external
module.exports = {
  before: {
    all: [],
    find: [
      // authenticate('jwt'),
      search(),
      search({
        fields: ['name', 'email']
      })
    ],
    get: [],
    create: [
      hashPassword(),
      lowerCase('email', 'username'),
      when(isProvider('external'),
        inviteCode.before
      ),
      // We don't need email verification
      // for server generated users
      addVerification(),
      when(isProvider('server'),
        hook => {
          hook.data.isVerified = true;
          return hook;
        }
      ),
      when(isProvider('external'),
        restrictUserRole(),
        createAdmin()
      ),
      saveRemoteImages(['avatar', 'coverImg'])
github Human-Connection / API / server / services / contributions / contributions.hooks.js View on Github external
module.exports = {
  before: {
    all: [
      softDelete(),
      xss({fields: xssFields})
    ],
    find: [
      iff(
        hook => hook.params.headers && hook.params.headers.authorization,
        authenticate('jwt')
      ),
      unless(isModerator(),
        excludeDisabled()
      ),
      excludeBlacklisted(),
      when(isProvider('server'),
        includeAll()
      ),
      search(),
      search({
        fields: ['title', 'content']
      })
    ],
    get: [
      unless(isModerator(),
        excludeDisabled()
      )
    ],
    create: [
      authenticate('jwt'),
      // Allow seeder to seed contributions
      associateCurrentUser(),
github Human-Connection / API / server / services / organizations / organizations.hooks.js View on Github external
restrictToOwnerOrModerator({ isEnabled: true, reviewedBy: { $ne: null } }),
      search(),
      search({
        fields: ['name', 'email']
      })
    ],
    get: [
      restrictToOwnerOrModerator({ isEnabled: true, reviewedBy: { $ne: null } })
    ],
    create: [
      authenticate('jwt'),
      // Allow seeder to seed contributions
      unless(isProvider('server'),
        isVerified()
      ),
      when(isModerator(),
        hook => {
          hook.data.reviewedBy = hook.params.user.userId;
          return hook;
        }
      ),
      associateCurrentUser(),
      createSlug({ field: 'name' }),
      createExcerpt({ field: 'description' }),
      saveRemoteImages(['logo', 'coverImg'])
    ],
    update: [
      authenticate('jwt'),
      unless(isProvider('server'),
        isVerified()
      ),
      stashBefore(),
github Human-Connection / API / server / services / users / users.hooks.js View on Github external
update: [
      ...restrict,
      hashPassword(),
      disableMultiItemChange(),
      lowerCase('email', 'username'),
      when(isProvider('external'),
        restrictUserRole()
      ),
      saveRemoteImages(['avatar', 'coverImg'])
    ],
    patch: [
      ...restrict,
      disableMultiItemChange(),
      lowerCase('email', 'username'),
      // Only set slug once
      when(
        hook => {
          return hook.params && hook.params.user && !hook.params.user.slug;
        },
        createSlug({ field: 'name' })
      ),
      when(isProvider('external'),
        restrictUserRole()
      ),
      saveRemoteImages(['avatar', 'coverImg'])
    ],
    remove: [
      ...restrict,
      disableMultiItemChange(),
      removeAllRelatedUserData()
    ]
  },
github kalisio / feathers-distributed / example / gateway / src / services / users / users.hooks.js View on Github external
];

module.exports = {
  before: {
    all: [],
    find: [ authenticate('jwt') ],
    get: [ ...restrict ],
    create: [ hashPassword() ],
    update: [ ...restrict, hashPassword() ],
    patch: [ ...restrict, hashPassword() ],
    remove: [ ...restrict ]
  },

  after: {
    all: [
      commonHooks.when(
        hook => hook.params.provider,
        commonHooks.discard('password')
      )
    ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [],
    find: [],
    get: [],
github mariusandra / insights / packages / insights-core / app / services / users / users.hooks.js View on Github external
]

module.exports = {
  before: {
    all: [],
    find: [],
    get: [ ...restrict ],
    create: [ hashPassword() ],
    update: [ ...restrict, hashPassword() ],
    patch: [ ...restrict, hashPassword() ],
    remove: [ ...restrict ]
  },

  after: {
    all: [
      commonHooks.when(
        hook => hook.params.provider,
        commonHooks.discard('password')
      )
    ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [],
    find: [],
    get: [],