From 3b0e3280421c94089cd86e833246daebe5424fc9 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Mon, 15 Mar 2021 21:27:35 +0300 Subject: feat: compute waybill name --- src/services/waybills.service.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src/services/waybills.service.ts') 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], }, }) }; -- cgit v1.2.3