Skip to content

Commit 681e51a

Browse files
committed
feat: setup hooks for VoteService
1 parent 34ec4c9 commit 681e51a

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

services/votes/votes.hooks.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
import { HookContext } from '@feathersjs/feathers';
12
import { authenticate } from '@feathersjs/authentication';
2-
import convertPoll from '../../hooks/convertPoll';
3+
4+
const addUserId = async (context: HookContext): Promise<HookContext> => {
5+
const { params: { user} } = context;
6+
context.data.userId = user._id;
7+
return context;
8+
};
39

410
export default {
511
before: {
6-
create: [authenticate('jwt')]
7-
},
8-
after: {
9-
all: [convertPoll]
12+
create: [authenticate('jwt'), addUserId]
1013
}
1114
};
1215

services/votes/votes.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import hooks from './votes.hooks';
77
const VoteService = service({ Model });
88

99
export default (app: Application): void => {
10-
app.use('/votes/', VoteService);
10+
app.use('/votes', VoteService);
1111
app.service('votes').hooks(hooks);
1212
};
1313

0 commit comments

Comments
 (0)