From 61939d8c23e72ddd995c9319577053fff5211184 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 14 Mar 2021 13:39:06 +0300 Subject: feat: populate Waybills --- src/services/waybills.service.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'src') diff --git a/src/services/waybills.service.ts b/src/services/waybills.service.ts index 7aea1e3..0744bee 100644 --- a/src/services/waybills.service.ts +++ b/src/services/waybills.service.ts @@ -1,10 +1,33 @@ import { Application } from '@feathersjs/express'; import service from 'feathers-mongoose'; +import { populate } from 'feathers-hooks-common'; import Model from '../models/waybill/waybill.model'; const waybills = service({ Model }); +const populateSchema = { + include: [ + { + service: 'contractors', + nameAs: 'contractor', + parentField: 'contractorId', + childField: '_id' + }, + { + service: 'products', + nameAs: 'product', + parentField: 'productId', + childField: '_id' + }, + ] +}; + export default (app: Application): void => { app.use('/waybills', waybills); + app.service('waybills').hooks({ + after: { + all: populate({ schema: populateSchema }), + }, + }) }; -- cgit v1.2.3