File tree Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Expand file tree Collapse file tree 3 files changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import _ from 'lodash' ;
2
+ import { Application } from '@feathersjs/express' ;
3
+ import { Params } from '@feathersjs/feathers' ;
4
+ import { Poll } from 'which-types' ;
5
+
6
+ import { PollSchema } from '../../models/polls/poll.schema' ;
7
+ import PollModel from '../../models/polls/poll.model' ;
8
+
9
+
10
+ export default class Feed {
11
+ app ! : Application ;
12
+
13
+ async find ( params : Params ) : Promise < Poll [ ] > {
14
+ return this . app . service ( 'polls' )
15
+ . find ( params )
16
+ . then ( // Move new verified polls on top
17
+ ( polls : Poll [ ] ) => _ . sortBy ( polls , poll => poll . author . verified && ! poll . userChoice )
18
+ ) . then ( // But all seen posts go down
19
+ ( polls : Poll [ ] ) => _ . sortBy ( polls , poll => ! ! poll . userChoice )
20
+ ) ;
21
+ }
22
+
23
+ setup ( app : Application ) {
24
+ this . app = app ;
25
+ }
26
+ }
27
+
Original file line number Diff line number Diff line change
1
+ import { Application } from '@feathersjs/express' ;
2
+ import Feed from './feed.class' ;
3
+
4
+ export default ( app : Application ) : void => {
5
+ app . use ( '/feed' , new Feed ( ) ) ;
6
+ } ;
7
+
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import Polls from './polls/polls.service';
4
4
import Profiles from './profiles/profiles.service' ;
5
5
import Votes from './votes/votes.service' ;
6
6
import Auth from './auth/auth.service' ;
7
+ import Feed from './feed/feed.service' ;
7
8
8
9
import tryAuthenticate from '../hooks/tryAuthenticate' ;
9
10
import logging from '../hooks/logging' ;
@@ -15,6 +16,7 @@ export default (app: Application): void => {
15
16
app . configure ( Polls ) ;
16
17
app . configure ( Profiles ) ;
17
18
app . configure ( Votes ) ;
19
+ app . configure ( Feed ) ;
18
20
19
21
app . hooks ( {
20
22
before : {
You can’t perform that action at this time.
0 commit comments