From a76ec7c41ebc5c208d7b31c81f8a659bd1be159c Mon Sep 17 00:00:00 2001 From: eug-vs Date: Tue, 16 Mar 2021 02:52:11 +0300 Subject: feat: populate name field in all endpoints --- src/services/waybills.service.ts | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'src/services/waybills.service.ts') 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 => { -- cgit v1.2.3