summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2021-03-16 02:52:11 +0300
committereug-vs <eug-vs@keemail.me>2021-03-16 02:52:11 +0300
commita76ec7c41ebc5c208d7b31c81f8a659bd1be159c (patch)
tree81e41ebdd6d9b6ffe178fff3afd33d20754741d2
parentcb8ffd12424c6ce8828f62779440f415a6c0be51 (diff)
downloadcommercel-api-a76ec7c41ebc5c208d7b31c81f8a659bd1be159c.tar.gz
feat: populate name field in all endpoints
-rw-r--r--src/services/waybills.service.ts18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/services/waybills.service.ts b/src/services/waybills.service.ts
index 961516e..5007fab 100644
--- a/src/services/waybills.service.ts
+++ b/src/services/waybills.service.ts
@@ -47,9 +47,21 @@ const performWaybillOperation = async (id: string, cancel = false) => {
};
const addName = (context: HookContext): HookContext => {
- const { result: { operation, product, quantity } } = context;
- const name = `Накладная: ${product?.name} ${operation === 'in' ? 'приход' : 'расход' } ${quantity} шт.`
- return _.set(context, 'result.name', name);
+ const { result } = context;
+
+ const addNameSingle = (item: any): void => {
+ const { operation, product, quantity } = item;
+ const op = operation === 'in' ? 'приход' : 'расход';
+ const name = `Накладная: ${product?.name} ${op} ${quantity} шт.`
+ return { name, ...item };
+ };
+
+ if (Array.isArray(result)) {
+ context.result = result.map(addNameSingle);
+ } else {
+ context.result = addNameSingle(result);
+ }
+ return context;
};
export default (app: Application): void => {