Skip to content

Commit 9a48836

Browse files
committed
feat: create feed service
1 parent 24119e5 commit 9a48836

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

services/feed/feed.class.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+

services/feed/feed.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+

services/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Polls from './polls/polls.service';
44
import Profiles from './profiles/profiles.service';
55
import Votes from './votes/votes.service';
66
import Auth from './auth/auth.service';
7+
import Feed from './feed/feed.service';
78

89
import tryAuthenticate from '../hooks/tryAuthenticate';
910
import logging from '../hooks/logging';
@@ -15,6 +16,7 @@ export default (app: Application): void => {
1516
app.configure(Polls);
1617
app.configure(Profiles);
1718
app.configure(Votes);
19+
app.configure(Feed);
1820

1921
app.hooks({
2022
before: {

0 commit comments

Comments
 (0)