import { Document , Model } from 'mongoose' ; import { RestgooseModel } from './restgoose-model' ; import { RestRequest } from './types' ; export function buildPayload < T extends RestgooseModel > ( req , modelType ) { const payload = { } ; const properties = Object . keys ( ( modelType . schema as any ) . tree ) ; properties . forEach ( ( prop ) => { if ( typeof ( req . body [ prop ] ) !== 'undefined' ) { payload [ prop ] = req . body [ prop ] ; } } ) ; return payload ; }