diff options
Diffstat (limited to 'services/feed/feed.hooks.ts')
-rw-r--r-- | services/feed/feed.hooks.ts | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/services/feed/feed.hooks.ts b/services/feed/feed.hooks.ts new file mode 100644 index 0000000..0e201db --- /dev/null +++ b/services/feed/feed.hooks.ts @@ -0,0 +1,28 @@ +import _ from 'lodash'; +import { HookContext } from '@feathersjs/feathers'; + + +const raiseNewVerifedPolls = async (context: HookContext): Promise<HookContext> => { + // Raise unseen verified polls to the very top + context.result = _.sortBy( + context.result, + poll => !(poll.author.verified && !poll.userChoice) + ); + return context; +}; + +const lowerOldPolls = async (context: HookContext): Promise<HookContext> => { + // Move all seen polls down + context.result = _.sortBy( + context.result, + poll => !!poll.userChoice + ); + return context; +}; + +export default { + after: { + find: [raiseNewVerifedPolls, lowerOldPolls] + } +}; + |