summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/services/waybills.service.ts10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/services/waybills.service.ts b/src/services/waybills.service.ts
index 0744bee..e947f0a 100644
--- a/src/services/waybills.service.ts
+++ b/src/services/waybills.service.ts
@@ -1,6 +1,8 @@
import { Application } from '@feathersjs/express';
+import { HookContext } from '@feathersjs/feathers';
import service from 'feathers-mongoose';
import { populate } from 'feathers-hooks-common';
+import _ from 'lodash';
import Model from '../models/waybill/waybill.model';
const waybills = service({ Model });
@@ -22,11 +24,17 @@ const populateSchema = {
]
};
+const addName = (context: HookContext): HookContext => {
+ const { result: { operation, product, quantity } } = context;
+ const name = `Накладная: ${product?.name} ${operation === 'in' ? 'приход' : 'расход' } ${quantity} шт.`
+ return _.set(context, 'result.name', name);
+};
+
export default (app: Application): void => {
app.use('/waybills', waybills);
app.service('waybills').hooks({
after: {
- all: populate({ schema: populateSchema }),
+ all: [populate({ schema: populateSchema }), addName],
},
})
};