diff options
-rw-r--r-- | hooks/sortByDate.ts | 8 | ||||
-rw-r--r-- | services/polls/polls.hooks.ts | 12 |
2 files changed, 11 insertions, 9 deletions
diff --git a/hooks/sortByDate.ts b/hooks/sortByDate.ts new file mode 100644 index 0000000..4a20920 --- /dev/null +++ b/hooks/sortByDate.ts @@ -0,0 +1,8 @@ +import _ from 'lodash'; +import { HookContext } from '@feathersjs/feathers'; + +export default async (context: HookContext): Promise<HookContext> => { + _.set(context, 'params.query.$sort', { createdAt: - 1}); + return context; +} + diff --git a/services/polls/polls.hooks.ts b/services/polls/polls.hooks.ts index 524eaee..77fcc7a 100644 --- a/services/polls/polls.hooks.ts +++ b/services/polls/polls.hooks.ts @@ -1,18 +1,12 @@ -import _ from 'lodash'; -import { HookContext } from '@feathersjs/feathers'; import convertPoll from '../../hooks/convertPoll'; - -const sort = async (context: HookContext): Promise<HookContext> => { - _.set(context, 'params.query.$sort', { createdAt: - 1}); - return context; -} +import sortByDate from '../../hooks/sortByDate'; export default { before: { - find: sort + find: sortByDate }, after: { - all: [convertPoll] + all: convertPoll } }; |