From cd284d9e4c1f28bf7c31c52d71e76878a3ff5f4a Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 20 Mar 2021 00:12:40 +0300 Subject: feat: move formatDate to hooks --- src/services/transfers.service.ts | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/services/transfers.service.ts (limited to 'src/services/transfers.service.ts') diff --git a/src/services/transfers.service.ts b/src/services/transfers.service.ts new file mode 100644 index 0000000..cf6a490 --- /dev/null +++ b/src/services/transfers.service.ts @@ -0,0 +1,32 @@ +import { Application } from '@feathersjs/express'; +import service from 'feathers-mongoose'; +import { populate } from 'feathers-hooks-common'; +import Model from '../models/transfer/transfer.model'; +import formatDate from '../hooks/formatDate'; + +const transfers = service({ Model }); + +const populateSchema = { + include: [ + { + service: 'contractors', + nameAs: 'contractor', + parentField: 'contractorId', + childField: '_id' + } + ] +}; + +export default (app: Application): void => { + app.use('/transfers', transfers); + + app.service('transfers').hooks({ + after: { + all: [ + populate({ schema: populateSchema }), + formatDate(), + ], + }, + }) +}; + -- cgit v1.2.3