From 681e51a658bfed723b368fc5b71b1350909d9496 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Thu, 25 Jun 2020 11:02:54 +0300 Subject: feat: setup hooks for VoteService --- services/votes/votes.hooks.ts | 13 ++++++++----- services/votes/votes.service.ts | 2 +- 2 files changed, 9 insertions(+), 6 deletions(-) (limited to 'services') diff --git a/services/votes/votes.hooks.ts b/services/votes/votes.hooks.ts index a41b8a9..63f19e3 100644 --- a/services/votes/votes.hooks.ts +++ b/services/votes/votes.hooks.ts @@ -1,12 +1,15 @@ +import { HookContext } from '@feathersjs/feathers'; import { authenticate } from '@feathersjs/authentication'; -import convertPoll from '../../hooks/convertPoll'; + +const addUserId = async (context: HookContext): Promise => { + const { params: { user} } = context; + context.data.userId = user._id; + return context; +}; export default { before: { - create: [authenticate('jwt')] - }, - after: { - all: [convertPoll] + create: [authenticate('jwt'), addUserId] } }; diff --git a/services/votes/votes.service.ts b/services/votes/votes.service.ts index 81f767c..cb40c1a 100644 --- a/services/votes/votes.service.ts +++ b/services/votes/votes.service.ts @@ -7,7 +7,7 @@ import hooks from './votes.hooks'; const VoteService = service({ Model }); export default (app: Application): void => { - app.use('/votes/', VoteService); + app.use('/votes', VoteService); app.service('votes').hooks(hooks); }; -- cgit v1.2.3