diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/services/transfers.service.ts | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/src/services/transfers.service.ts b/src/services/transfers.service.ts index cf6a490..1d7bdaf 100644 --- a/src/services/transfers.service.ts +++ b/src/services/transfers.service.ts @@ -1,6 +1,6 @@ import { Application } from '@feathersjs/express'; import service from 'feathers-mongoose'; -import { populate } from 'feathers-hooks-common'; +import { populate, alterItems } from 'feathers-hooks-common'; import Model from '../models/transfer/transfer.model'; import formatDate from '../hooks/formatDate'; @@ -17,6 +17,13 @@ const populateSchema = { ] }; +const addFields = (item: any) => { + const { operation, contractor, amount } = item; + const op = operation === 'in' ? 'приход' : 'расход'; + const name = `Перевод: ${op} $${amount} от ${contractor.name}`; + return { ...item, name }; +}; + export default (app: Application): void => { app.use('/transfers', transfers); @@ -24,6 +31,7 @@ export default (app: Application): void => { after: { all: [ populate({ schema: populateSchema }), + alterItems(addFields), formatDate(), ], }, |