Skip to content

Commit 187085e

Browse files
committed
feat: allow querying users by regex
1 parent 990edc9 commit 187085e

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

services/users/users.hooks.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import _ from 'lodash';
12
import { hooks } from '@feathersjs/authentication-local';
23
import { HookContext } from '@feathersjs/feathers';
34

@@ -8,15 +9,23 @@ const localDispatch = async (context: HookContext): Promise<HookContext> => {
89
return context;
910
};
1011

12+
const ignoreCaseRegex = async (context: HookContext): Promise<HookContext> => {
13+
context.params.query = _.mapValues(context.params.query, data => {
14+
return _.set(data, '$options', 'i');
15+
});
16+
return context;
17+
};
18+
1119
export default {
1220
after: {
13-
all: [hooks.protect('password')],
14-
get: [localDispatch] // Protect password from local get's
21+
all: hooks.protect('password'),
22+
get: localDispatch, // Protect password from local get's
1523
},
1624
before: {
17-
create: [hashPassword],
18-
patch: [hashPassword],
19-
update: [hashPassword]
25+
find: ignoreCaseRegex,
26+
create: hashPassword,
27+
patch: hashPassword,
28+
update: hashPassword
2029
}
2130
};
2231

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)