diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/hooks/sortByDate.ts | 8 | ||||
-rw-r--r-- | src/services/index.ts | 7 |
2 files changed, 15 insertions, 0 deletions
diff --git a/src/hooks/sortByDate.ts b/src/hooks/sortByDate.ts new file mode 100644 index 0000000..9dd1222 --- /dev/null +++ b/src/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/src/services/index.ts b/src/services/index.ts index 2c3430c..42b1fbd 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -5,6 +5,7 @@ import Waybills from './waybills.service'; import Tranfers from './transfers.service'; import Spreadsheets from './spreadsheets.service'; import Uploads from './uploads.service'; +import sortByDate from '../hooks/sortByDate'; export default (app: Application): void => { app.configure(Products); @@ -15,4 +16,10 @@ export default (app: Application): void => { app.configure(Uploads); app.get('/ping', (req, res) => res.send('pong')); + + app.hooks({ + before: { + find: sortByDate + }, + }) }; |