Skip to content

Commit 8baf96b

Browse files
authored
Merge pull request #15 from which-ecosystem/search
Allow searching users
2 parents 990edc9 + bdd8b94 commit 8baf96b

File tree

4 files changed

+16
-10
lines changed

4 files changed

+16
-10
lines changed

hooks/isAuthenticated.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { HookContext } from '@feathersjs/feathers';
22

33
export default async (context: HookContext): Promise<boolean> => {
4-
console.log(context.params.authenticated);
54
return context.params.authenticated || false;
65
};
76

services/profiles/profiles.class.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
import { Application } from '@feathersjs/express';
2+
import { Params } from '@feathersjs/feathers';
23
import { Poll } from 'which-types';
34

45

56
export default class Profiles {
67
app!: Application;
78

8-
async get(id: string): Promise<Poll[]> {
9+
async get(id: string, params: Params): Promise<Poll[]> {
910
return this.app.service('polls').find({
11+
...params,
1012
query: {
1113
authorId: id
1214
}

services/users/users.hooks.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
1+
import _ from 'lodash';
12
import { hooks } from '@feathersjs/authentication-local';
3+
import { discard } from 'feathers-hooks-common';
24
import { HookContext } from '@feathersjs/feathers';
35

46
const hashPassword = hooks.hashPassword('password');
57

6-
const localDispatch = async (context: HookContext): Promise<HookContext> => {
7-
context.result = context.dispatch;
8+
const ignoreCaseRegex = async (context: HookContext): Promise<HookContext> => {
9+
context.params.query = _.mapValues(context.params.query, data => {
10+
return _.set(data, '$options', 'i');
11+
});
812
return context;
913
};
1014

1115
export default {
1216
after: {
13-
all: [hooks.protect('password')],
14-
get: [localDispatch] // Protect password from local get's
17+
all: hooks.protect('password'),
18+
get: discard('password') // Protect password from local get's
1519
},
1620
before: {
17-
create: [hashPassword],
18-
patch: [hashPassword],
19-
update: [hashPassword]
21+
find: ignoreCaseRegex,
22+
create: hashPassword,
23+
patch: hashPassword,
24+
update: hashPassword
2025
}
2126
};
2227

services/users/users.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import service from 'feathers-mongoose';
33
import Model from '../../models/users/user.model';
44
import hooks from './users.hooks';
55

6-
const UserService = service({ Model });
6+
const UserService = service({ Model, whitelist: ['$options', '$regex'] });
77

88
export default (app: Application): void => {
99
app.use('/users', UserService);

0 commit comments

Comments
 (0)