diff options
Diffstat (limited to 'services/feed/feed.class.ts')
-rw-r--r-- | services/feed/feed.class.ts | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/services/feed/feed.class.ts b/services/feed/feed.class.ts new file mode 100644 index 0000000..8c7cd0b --- /dev/null +++ b/services/feed/feed.class.ts @@ -0,0 +1,27 @@ +import _ from 'lodash'; +import { Application } from '@feathersjs/express'; +import { Params } from '@feathersjs/feathers'; +import { Poll } from 'which-types'; + +import { PollSchema } from '../../models/polls/poll.schema'; +import PollModel from '../../models/polls/poll.model'; + + +export default class Feed { + app!: Application; + + async find(params: Params): Promise<Poll[]> { + return this.app.service('polls') + .find(params) + .then( // Move new verified polls on top + (polls: Poll[]) => _.sortBy(polls, poll => poll.author.verified && !poll.userChoice) + ).then( // But all seen posts go down + (polls: Poll[]) => _.sortBy(polls, poll => !!poll.userChoice) + ); + } + + setup (app: Application) { + this.app = app; + } +} + |