File tree Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Expand file tree Collapse file tree 2 files changed +26
-4
lines changed Original file line number Diff line number Diff line change @@ -76,6 +76,31 @@ describe('Utils', () => {
7676 expect ( serializeEntity ( rhcp , [ ] ) ) . not . toHaveProperty ( 'temporaryName' ) ;
7777 } ) ;
7878
79+ it ( 'should not return getter properties with an Ignore() decorator' , ( ) => {
80+ class Band implements IEntity {
81+ id : string ;
82+ name : string ;
83+
84+ get removeFirstLetterOfName ( ) {
85+ if ( ! this . name ) return '' ;
86+ return this . name . charAt ( 0 ) ;
87+ }
88+
89+ @Ignore ( )
90+ get capitalizedName ( ) {
91+ if ( ! this . name ) return '' ;
92+ return this . name . charAt ( 0 ) . toUpperCase ( ) + this . name . slice ( 1 ) ;
93+ }
94+ }
95+
96+ const rhcp = new Band ( ) ;
97+ rhcp . name = 'red Hot Chili Peppers' ;
98+
99+ expect ( serializeEntity ( rhcp , [ ] ) ) . toHaveProperty ( 'name' ) ;
100+ expect ( serializeEntity ( rhcp , [ ] ) ) . toHaveProperty ( 'removeFirstLetterOfName' ) ;
101+ expect ( serializeEntity ( rhcp , [ ] ) ) . not . toHaveProperty ( 'capitalizedName' ) ;
102+ } ) ;
103+
79104 it ( 'should serialize object properties with the @Serialize() decorator' , ( ) => {
80105 class Address {
81106 streetName : string ;
Original file line number Diff line number Diff line change @@ -55,13 +55,10 @@ export function serializeEntity<T extends IEntity>(
5555 delete serializableObj [ scm . propertyKey ] ;
5656 } ) ;
5757
58- Object . keys ( obj ) . forEach ( propertyKey => {
58+ Object . entries ( serializableObj ) . forEach ( ( [ propertyKey , propertyValue ] ) => {
5959 if ( Reflect . getMetadata ( ignoreKey , obj , propertyKey ) === true ) {
6060 delete serializableObj [ propertyKey ] ;
6161 }
62- } ) ;
63-
64- Object . entries ( serializableObj ) . forEach ( ( [ propertyKey , propertyValue ] ) => {
6562 if ( Reflect . getMetadata ( serializeKey , obj , propertyKey ) !== undefined ) {
6663 if ( Array . isArray ( propertyValue ) ) {
6764 ( serializableObj as { [ key : string ] : unknown } ) [ propertyKey ] = propertyValue . map ( element =>
You can’t perform that action at this time.
0 commit comments