Skip to content

Commit 0a78ac4

Browse files
committed
refactor: move sortByDate hook to global hooks
1 parent 9a48836 commit 0a78ac4

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

hooks/sortByDate.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import _ from 'lodash';
2+
import { HookContext } from '@feathersjs/feathers';
3+
4+
export default async (context: HookContext): Promise<HookContext> => {
5+
_.set(context, 'params.query.$sort', { createdAt: - 1});
6+
return context;
7+
}
8+

services/polls/polls.hooks.ts

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
1-
import _ from 'lodash';
2-
import { HookContext } from '@feathersjs/feathers';
31
import convertPoll from '../../hooks/convertPoll';
4-
5-
const sort = async (context: HookContext): Promise<HookContext> => {
6-
_.set(context, 'params.query.$sort', { createdAt: - 1});
7-
return context;
8-
}
2+
import sortByDate from '../../hooks/sortByDate';
93

104
export default {
115
before: {
12-
find: sort
6+
find: sortByDate
137
},
148
after: {
15-
all: [convertPoll]
9+
all: convertPoll
1610
}
1711
};
1812

0 commit comments

Comments
 (0)