diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-28 00:57:52 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-28 01:14:59 +0300 |
commit | 187085ec11fe9ab744a9105dfd258254b2ddd35c (patch) | |
tree | eb153f6ca63339dc4351f7630e0ed621f1f925be | |
parent | 990edc953d734b1f1621fc0f5161c1eb978a3ea0 (diff) | |
download | which-api-187085ec11fe9ab744a9105dfd258254b2ddd35c.tar.gz |
feat: allow querying users by regex
-rw-r--r-- | services/users/users.hooks.ts | 19 | ||||
-rw-r--r-- | services/users/users.service.ts | 2 |
2 files changed, 15 insertions, 6 deletions
diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts index ee1ae1c..398d058 100644 --- a/services/users/users.hooks.ts +++ b/services/users/users.hooks.ts @@ -1,3 +1,4 @@ +import _ from 'lodash'; import { hooks } from '@feathersjs/authentication-local'; import { HookContext } from '@feathersjs/feathers'; @@ -8,15 +9,23 @@ const localDispatch = async (context: HookContext): Promise<HookContext> => { return context; }; +const ignoreCaseRegex = async (context: HookContext): Promise<HookContext> => { + context.params.query = _.mapValues(context.params.query, data => { + return _.set(data, '$options', 'i'); + }); + return context; +}; + export default { after: { - all: [hooks.protect('password')], - get: [localDispatch] // Protect password from local get's + all: hooks.protect('password'), + get: localDispatch, // Protect password from local get's }, before: { - create: [hashPassword], - patch: [hashPassword], - update: [hashPassword] + find: ignoreCaseRegex, + create: hashPassword, + patch: hashPassword, + update: hashPassword } }; diff --git a/services/users/users.service.ts b/services/users/users.service.ts index 08c347d..77eb9fd 100644 --- a/services/users/users.service.ts +++ b/services/users/users.service.ts @@ -3,7 +3,7 @@ import service from 'feathers-mongoose'; import Model from '../../models/users/user.model'; import hooks from './users.hooks'; -const UserService = service({ Model }); +const UserService = service({ Model, whitelist: ['$options', '$regex'] }); export default (app: Application): void => { app.use('/users', UserService); |