summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-15 21:27:35 +0300
committereug-vs <eug-vs@keemail.me>2021-03-15 21:27:35 +0300
commit3b0e3280421c94089cd86e833246daebe5424fc9 (patch)
tree71241d26aceb38e0f21b3f78543e8225d61edf90
parent61939d8c23e72ddd995c9319577053fff5211184 (diff)
downloadcommercel-api-3b0e3280421c94089cd86e833246daebe5424fc9.tar.gz
feat: compute waybill name
-rw-r--r--package.json1
-rw-r--r--src/services/waybills.service.ts10
-rw-r--r--yarn.lock5
3 files changed, 15 insertions, 1 deletions
diff --git a/package.json b/package.json
index ef74095..254abd0 100644
--- a/package.json
+++ b/package.json
@@ -20,6 +20,7 @@
"devDependencies": {
"@types/bluebird": "^3.5.33",
"@types/cors": "^2.8.10",
+ "@types/lodash": "^4.14.168",
"@types/mongoose": "^5.10.3"
}
}
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],
},
})
};
diff --git a/yarn.lock b/yarn.lock
index e7be360..4cd23ed 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -131,6 +131,11 @@
"@types/qs" "*"
"@types/serve-static" "*"
+"@types/lodash@^4.14.168":
+ version "4.14.168"
+ resolved "https://registry.yarnpkg.com/@types/lodash/-/lodash-4.14.168.tgz#fe24632e79b7ade3f132891afff86caa5e5ce008"
+ integrity sha512-oVfRvqHV/V6D1yifJbVRU3TMp8OT6o6BG+U9MkwuJ3U8/CsDHvalRpsxBqivn71ztOFZBTfJMvETbqHiaNSj7Q==
+
"@types/mime@^1":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@types/mime/-/mime-1.3.2.tgz#93e25bf9ee75fe0fd80b594bc4feb0e862111b5a"