File tree Expand file tree Collapse file tree 3 files changed +32
-11
lines changed Expand file tree Collapse file tree 3 files changed +32
-11
lines changed Original file line number Diff line number Diff line change 1
- import _ from 'lodash' ;
2
1
import { Application } from '@feathersjs/express' ;
3
2
import { Params } from '@feathersjs/feathers' ;
4
3
import { Poll } from 'which-types' ;
5
4
6
- import { PollSchema } from '../../models/polls/poll.schema' ;
7
- import PollModel from '../../models/polls/poll.model' ;
8
-
9
5
10
6
export default class Feed {
11
7
app ! : Application ;
12
8
13
9
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
- ) ;
10
+ return this . app . service ( 'polls' ) . find ( params ) ;
21
11
}
22
12
23
13
setup ( app : Application ) {
Original file line number Diff line number Diff line change
1
+ import _ from 'lodash' ;
2
+ import { HookContext } from '@feathersjs/feathers' ;
3
+
4
+
5
+ const raiseNewVerifedPolls = async ( context : HookContext ) : Promise < HookContext > => {
6
+ // Raise unseen verified polls to the very top
7
+ context . result = _ . sortBy (
8
+ context . result ,
9
+ poll => ! ( poll . author . verified && ! poll . userChoice )
10
+ ) ;
11
+ return context ;
12
+ } ;
13
+
14
+ const lowerOldPolls = async ( context : HookContext ) : Promise < HookContext > => {
15
+ // Move all seen polls down
16
+ context . result = _ . sortBy (
17
+ context . result ,
18
+ poll => ! ! poll . userChoice
19
+ ) ;
20
+ return context ;
21
+ } ;
22
+
23
+ export default {
24
+ after : {
25
+ find : [ raiseNewVerifedPolls , lowerOldPolls ]
26
+ }
27
+ } ;
28
+
Original file line number Diff line number Diff line change 1
1
import { Application } from '@feathersjs/express' ;
2
2
import Feed from './feed.class' ;
3
3
4
+ import hooks from './feed.hooks' ;
5
+
4
6
export default ( app : Application ) : void => {
5
7
app . use ( '/feed' , new Feed ( ) ) ;
8
+ app . service ( 'feed' ) . hooks ( hooks ) ;
6
9
} ;
7
10
You can’t perform that action at this time.
0 commit comments