aboutsummaryrefslogtreecommitdiff
path: root/services
diff options
context:
space:
mode:
authorEugene Sokolov <eug-vs@keemail.me>2020-06-25 14:39:21 +0300
committerGitHub <noreply@github.com>2020-06-25 14:39:21 +0300
commit0afe8f1530affad1e58a65385b2a4bf888ab86cb (patch)
tree3bd5599bc5c3ce23777c5b369eaadd744f3c5c1f /services
parente488591b9548264d0305a5f34786138bd6c6622b (diff)
parent64f5f8c3f9660f649dfdaad07d84aa8c26b9661e (diff)
downloadwhich-api-0afe8f1530affad1e58a65385b2a4bf888ab86cb.tar.gz
Merge pull request #8 from which-ecosystem/votes
Votes
Diffstat (limited to 'services')
-rw-r--r--services/auth/auth.service.ts2
-rw-r--r--services/index.ts10
-rw-r--r--services/polls/polls.hooks.ts8
-rw-r--r--services/profiles/profiles.hooks.ts6
-rw-r--r--services/users/users.hooks.ts10
-rw-r--r--services/votes/votes.hooks.ts15
-rw-r--r--services/votes/votes.service.ts13
7 files changed, 51 insertions, 13 deletions
diff --git a/services/auth/auth.service.ts b/services/auth/auth.service.ts
index 42846b0..826357c 100644
--- a/services/auth/auth.service.ts
+++ b/services/auth/auth.service.ts
@@ -1,6 +1,6 @@
import {
AuthenticationService,
- JWTStrategy
+ JWTStrategy
} from '@feathersjs/authentication';
import { LocalStrategy } from '@feathersjs/authentication-local';
import { Application } from '@feathersjs/express';
diff --git a/services/index.ts b/services/index.ts
index f000837..fe5ffdc 100644
--- a/services/index.ts
+++ b/services/index.ts
@@ -2,12 +2,22 @@ import { Application } from '@feathersjs/express';
import Users from './users/users.service';
import Polls from './polls/polls.service';
import Profiles from './profiles/profiles.service';
+import Votes from './votes/votes.service';
import Auth from './auth/auth.service';
+import tryAuthenticate from '../hooks/tryAuthenticate';
+
export default (app: Application): void => {
app.configure(Auth);
app.configure(Users);
app.configure(Polls);
app.configure(Profiles);
+ app.configure(Votes);
+
+ app.hooks({
+ before: {
+ all: tryAuthenticate
+ }
+ })
};
diff --git a/services/polls/polls.hooks.ts b/services/polls/polls.hooks.ts
index 0637320..eba3e63 100644
--- a/services/polls/polls.hooks.ts
+++ b/services/polls/polls.hooks.ts
@@ -1,12 +1,8 @@
-import {
- expandAuthorHook,
- expandAuthorManyHook
-} from '../../hooks/expandAuthor';
+import convertPoll from '../../hooks/convertPoll';
export default {
after: {
- get: [expandAuthorHook],
- find: [expandAuthorManyHook]
+ all: [convertPoll],
}
};
diff --git a/services/profiles/profiles.hooks.ts b/services/profiles/profiles.hooks.ts
index bb05d94..13d6f63 100644
--- a/services/profiles/profiles.hooks.ts
+++ b/services/profiles/profiles.hooks.ts
@@ -1,10 +1,8 @@
-import {
- expandAuthorManyHook
-} from '../../hooks/expandAuthor';
+import convertPoll from '../../hooks/convertPoll';
export default {
after: {
- get: [expandAuthorManyHook]
+ all: [convertPoll]
}
};
diff --git a/services/users/users.hooks.ts b/services/users/users.hooks.ts
index fc17ed7..8eecca3 100644
--- a/services/users/users.hooks.ts
+++ b/services/users/users.hooks.ts
@@ -1,11 +1,17 @@
import { hooks } from '@feathersjs/authentication-local';
+import { HookContext } from '@feathersjs/feathers';
const hashPassword = hooks.hashPassword('password');
-const protectPassword = hooks.protect('password');
+
+const localDispatch = async (context: HookContext): Promise<HookContext> => {
+ context.result = context.dispatch;
+ return context;
+}
export default {
after: {
- all: [protectPassword]
+ all: [hooks.protect('password')],
+ get: [localDispatch] // Protect password from local get's
},
before: {
create: [hashPassword],
diff --git a/services/votes/votes.hooks.ts b/services/votes/votes.hooks.ts
new file mode 100644
index 0000000..1cf7261
--- /dev/null
+++ b/services/votes/votes.hooks.ts
@@ -0,0 +1,15 @@
+import { HookContext } from '@feathersjs/feathers';
+import requireAuth from '../../hooks/requireAuth';
+
+const addUserId = async (context: HookContext): Promise<HookContext> => {
+ const { params: { user} } = context;
+ context.data.userId = user._id;
+ return context;
+};
+
+export default {
+ before: {
+ create: [requireAuth, addUserId]
+ }
+};
+
diff --git a/services/votes/votes.service.ts b/services/votes/votes.service.ts
new file mode 100644
index 0000000..cb40c1a
--- /dev/null
+++ b/services/votes/votes.service.ts
@@ -0,0 +1,13 @@
+import { Application } from '@feathersjs/express';
+import service from 'feathers-mongoose';
+import Model from '../../models/votes/vote.model';
+
+import hooks from './votes.hooks';
+
+const VoteService = service({ Model });
+
+export default (app: Application): void => {
+ app.use('/votes', VoteService);
+ app.service('votes').hooks(hooks);
+};
+