diff options
author | eug-vs <eug-vs@keemail.me> | 2020-06-27 00:53:48 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2020-06-27 00:53:48 +0300 |
commit | 0a78ac48ed5ae37f88e5f36194953424a5bc18a0 (patch) | |
tree | 64578f493cf220112f53711d0b99f678c79fa6a4 | |
parent | 9a488369a481d92fed348df3de71bf612c4183d5 (diff) | |
download | which-api-0a78ac48ed5ae37f88e5f36194953424a5bc18a0.tar.gz |
refactor: move sortByDate hook to global hooks
-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 } }; |