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 /services/users/users.hooks.ts | |
parent | 990edc953d734b1f1621fc0f5161c1eb978a3ea0 (diff) | |
download | which-api-187085ec11fe9ab744a9105dfd258254b2ddd35c.tar.gz |
feat: allow querying users by regex
Diffstat (limited to 'services/users/users.hooks.ts')
-rw-r--r-- | services/users/users.hooks.ts | 19 |
1 files changed, 14 insertions, 5 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 } }; |