77import { omit } from 'lodash' ;
88import { DECORATORS } from '../constants' ;
99import { ApiProperty } from '../decorators' ;
10+ import { MetadataLoader } from '../plugin/metadata-loader' ;
1011import { ModelPropertiesAccessor } from '../services/model-properties-accessor' ;
1112import { clonePluginMetadataFactory } from './mapped-types.utils' ;
1213
@@ -15,7 +16,7 @@ const modelPropertiesAccessor = new ModelPropertiesAccessor();
1516export function OmitType < T , K extends keyof T > (
1617 classRef : Type < T > ,
1718 keys : readonly K [ ]
18- ) : Type < Omit < T , typeof keys [ number ] > > {
19+ ) : Type < Omit < T , ( typeof keys ) [ number ] > > {
1920 const fields = modelPropertiesAccessor
2021 . getModelProperties ( classRef . prototype )
2122 . filter ( ( item ) => ! keys . includes ( item as K ) ) ;
@@ -31,20 +32,32 @@ export function OmitType<T, K extends keyof T>(
3132 inheritValidationMetadata ( classRef , OmitTypeClass , isInheritedPredicate ) ;
3233 inheritTransformationMetadata ( classRef , OmitTypeClass , isInheritedPredicate ) ;
3334
34- clonePluginMetadataFactory (
35- OmitTypeClass as Type < unknown > ,
36- classRef . prototype ,
37- ( metadata : Record < string , any > ) => omit ( metadata , keys )
38- ) ;
39-
40- fields . forEach ( ( propertyKey ) => {
41- const metadata = Reflect . getMetadata (
42- DECORATORS . API_MODEL_PROPERTIES ,
35+ function applyFields ( fields : string [ ] ) {
36+ clonePluginMetadataFactory (
37+ OmitTypeClass as Type < unknown > ,
4338 classRef . prototype ,
44- propertyKey
39+ ( metadata : Record < string , any > ) => omit ( metadata , keys )
4540 ) ;
46- const decoratorFactory = ApiProperty ( metadata ) ;
47- decoratorFactory ( OmitTypeClass . prototype , propertyKey ) ;
41+
42+ fields . forEach ( ( propertyKey ) => {
43+ const metadata = Reflect . getMetadata (
44+ DECORATORS . API_MODEL_PROPERTIES ,
45+ classRef . prototype ,
46+ propertyKey
47+ ) ;
48+ const decoratorFactory = ApiProperty ( metadata ) ;
49+ decoratorFactory ( OmitTypeClass . prototype , propertyKey ) ;
50+ } ) ;
51+ }
52+ applyFields ( fields ) ;
53+
54+ MetadataLoader . addRefreshHook ( ( ) => {
55+ const fields = modelPropertiesAccessor
56+ . getModelProperties ( classRef . prototype )
57+ . filter ( ( item ) => ! keys . includes ( item as K ) ) ;
58+
59+ applyFields ( fields ) ;
4860 } ) ;
49- return OmitTypeClass as Type < Omit < T , typeof keys [ number ] > > ;
61+
62+ return OmitTypeClass as Type < Omit < T , ( typeof keys ) [ number ] > > ;
5063}
0 commit comments