diff options
Diffstat (limited to 'src/services/waybills.service.ts')
-rw-r--r-- | src/services/waybills.service.ts | 18 |
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 => { |