diff options
author | eug-vs <eug-vs@keemail.me> | 2021-03-15 21:27:35 +0300 |
---|---|---|
committer | eug-vs <eug-vs@keemail.me> | 2021-03-15 21:27:35 +0300 |
commit | 3b0e3280421c94089cd86e833246daebe5424fc9 (patch) | |
tree | 71241d26aceb38e0f21b3f78543e8225d61edf90 /src/services | |
parent | 61939d8c23e72ddd995c9319577053fff5211184 (diff) | |
download | commercel-api-3b0e3280421c94089cd86e833246daebe5424fc9.tar.gz |
feat: compute waybill name
Diffstat (limited to 'src/services')
-rw-r--r-- | src/services/waybills.service.ts | 10 |
1 files changed, 9 insertions, 1 deletions
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], }, }) }; |