import { PipeTransform , Injectable , ArgumentMetadata } from '@nestjs/common' ; /**
 * Strip undefined properties from body.
 */ @ Injectable ( ) export class StripUndefinedPipe implements PipeTransform { transform ( value , metadata ) { if ( metadata . type === 'body' ) { this . dropUndefined ( value ) ; return value ; } return value ; } private dropUndefined ( obj ) { for ( const key of Object . keys ( obj ) ) { if ( obj [ key ] === undefined ) { delete obj [ key ] ; } else if ( typeof obj [ key ] === 'object' && obj [ key ] !== null ) { this . dropUndefined ( obj [ key ] ) ; } } } }