diff options
Diffstat (limited to 'services')
-rw-r--r-- | services/feed/feed.class.ts | 27 | ||||
-rw-r--r-- | services/feed/feed.service.ts | 7 | ||||
-rw-r--r-- | services/index.ts | 2 |
3 files changed, 36 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; + } +} + diff --git a/services/feed/feed.service.ts b/services/feed/feed.service.ts new file mode 100644 index 0000000..f641425 --- /dev/null +++ b/services/feed/feed.service.ts @@ -0,0 +1,7 @@ +import { Application } from '@feathersjs/express'; +import Feed from './feed.class'; + +export default (app: Application): void => { + app.use('/feed', new Feed()); +}; + diff --git a/services/index.ts b/services/index.ts index bdce04f..1763a17 100644 --- a/services/index.ts +++ b/services/index.ts @@ -4,6 +4,7 @@ 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 Feed from './feed/feed.service'; import tryAuthenticate from '../hooks/tryAuthenticate'; import logging from '../hooks/logging'; @@ -15,6 +16,7 @@ export default (app: Application): void => { app.configure(Polls); app.configure(Profiles); app.configure(Votes); + app.configure(Feed); app.hooks({ before: { |