diff options
author | Eugene Sokolov <eug-vs@keemail.me> | 2020-06-28 04:13:13 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-28 04:13:13 +0300 |
commit | 8baf96be5ea7880cebe3aeda733b9196950be434 (patch) | |
tree | 060c38efa99810284f47411041c45952c6817361 | |
parent | 990edc953d734b1f1621fc0f5161c1eb978a3ea0 (diff) | |
parent | bdd8b947e89400606ec1d7e1bd04f3794e942c12 (diff) | |
download | which-api-8baf96be5ea7880cebe3aeda733b9196950be434.tar.gz |
Merge pull request #15 from which-ecosystem/search
Allow searching users
-rw-r--r-- | hooks/isAuthenticated.ts | 1 | ||||
-rw-r--r-- | services/profiles/profiles.class.ts | 4 | ||||
-rw-r--r-- | services/users/users.hooks.ts | 19 | ||||
-rw-r--r-- | services/users/users.service.ts | 2 |
4 files changed, 16 insertions, 10 deletions
diff --git a/hooks/isAuthenticated.ts b/hooks/isAuthenticated.ts index 50290c8..077fbec 100644 --- a/hooks/isAuthenticated.ts +++ b/hooks/isAuthenticated.ts @@ -1,7 +1,6 @@ import { HookContext } from '@feathersjs/feathers'; export default async (context: HookContext): Promise<boolean> => { - console.log(context.params.authenticated); return context.params.authenticated || false; }; diff --git a/services/profiles/profiles.class.ts b/services/profiles/profiles.class.ts index 3461cbc..a6de474 100644 --- a/services/profiles/profiles.class.ts +++ b/services/profiles/profiles.class.ts @@ -1,12 +1,14 @@ import { Application } from '@feathersjs/express'; +import { Params } from '@feathersjs/feathers'; import { Poll } from 'which-types'; export default class Profiles { app!: Application; - async get(id: string): Promise<Poll[]> { + async get(id: string, params: Params): Promise<Poll[]> { return this.app.service('polls').find({ + ...params, query: { authorId: id } diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts index ee1ae1c..48843be 100644 --- a/services/users/users.hooks.ts +++ b/services/users/users.hooks.ts @@ -1,22 +1,27 @@ +import _ from 'lodash'; import { hooks } from '@feathersjs/authentication-local'; +import { discard } from 'feathers-hooks-common'; import { HookContext } from '@feathersjs/feathers'; const hashPassword = hooks.hashPassword('password'); -const localDispatch = async (context: HookContext): Promise<HookContext> => { - context.result = context.dispatch; +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: discard('password') // 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); |