summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-20 00:18:26 +0300
committereug-vs <eug-vs@keemail.me>2021-03-20 00:18:26 +0300
commitd6b46d8cad8dce2dafc878dfae53c71bdda39dd0 (patch)
treef1a8aca94828ee6a84650715e069c7eb39ac205c
parentcd284d9e4c1f28bf7c31c52d71e76878a3ff5f4a (diff)
downloadcommercel-api-d6b46d8cad8dce2dafc878dfae53c71bdda39dd0.tar.gz
feat: add name to Transfer
-rw-r--r--src/services/transfers.service.ts10
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(),
],
},