From 9a488369a481d92fed348df3de71bf612c4183d5 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 27 Jun 2020 00:18:32 +0300 Subject: feat: create feed service --- services/feed/feed.class.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 services/feed/feed.class.ts (limited to 'services/feed/feed.class.ts') 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 { + 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; + } +} + -- cgit v1.2.3 From 7c2d12b4f809563cc08e86229359251674b745ce Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 27 Jun 2020 01:17:42 +0300 Subject: refactor: improve Feed service --- services/feed/feed.class.ts | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) (limited to 'services/feed/feed.class.ts') diff --git a/services/feed/feed.class.ts b/services/feed/feed.class.ts index 8c7cd0b..3a2ffe4 100644 --- a/services/feed/feed.class.ts +++ b/services/feed/feed.class.ts @@ -1,23 +1,13 @@ -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 { - 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) - ); + return this.app.service('polls').find(params); } setup (app: Application) { -- cgit v1.2.3 From a8c74bf2c5b8a8cc0bfd0f1d082eb3bf8357f6bc Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 27 Jun 2020 01:26:03 +0300 Subject: style: fix linting errors --- services/feed/feed.class.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'services/feed/feed.class.ts') diff --git a/services/feed/feed.class.ts b/services/feed/feed.class.ts index 3a2ffe4..ceb86e6 100644 --- a/services/feed/feed.class.ts +++ b/services/feed/feed.class.ts @@ -10,7 +10,7 @@ export default class Feed { return this.app.service('polls').find(params); } - setup (app: Application) { + setup(app: Application): void { this.app = app; } } -- cgit v1.2.3