From 24376076e0b2c37baaf196f0664078840aeec91b Mon Sep 17 00:00:00 2001 From: eug-vs Date: Fri, 26 Jun 2020 22:12:37 +0300 Subject: feat: sort polls by date (newest on top) --- services/polls/polls.hooks.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'services/polls') diff --git a/services/polls/polls.hooks.ts b/services/polls/polls.hooks.ts index 13d6f63..524eaee 100644 --- a/services/polls/polls.hooks.ts +++ b/services/polls/polls.hooks.ts @@ -1,6 +1,16 @@ +import _ from 'lodash'; +import { HookContext } from '@feathersjs/feathers'; import convertPoll from '../../hooks/convertPoll'; +const sort = async (context: HookContext): Promise => { + _.set(context, 'params.query.$sort', { createdAt: - 1}); + return context; +} + export default { + before: { + find: sort + }, after: { all: [convertPoll] } -- cgit v1.2.3