From d6b46d8cad8dce2dafc878dfae53c71bdda39dd0 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 20 Mar 2021 00:18:26 +0300 Subject: feat: add name to Transfer --- src/services/transfers.service.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) 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(), ], }, -- cgit v1.2.3