From 2e4ec7de39c0751a75086d9e97daf2bf50b47ec3 Mon Sep 17 00:00:00 2001 From: Chau Tran Date: Mon, 10 Feb 2020 17:12:19 -0600 Subject: [PATCH] fix(metadata-explorer.ts): fix missing props from base class --- src/metadata-explorer.ts | 8 +++++++- test/metadata-manager.test.ts | 9 ++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/metadata-explorer.ts b/src/metadata-explorer.ts index 2f912ddca..ccb3b8c52 100644 --- a/src/metadata-explorer.ts +++ b/src/metadata-explorer.ts @@ -60,8 +60,14 @@ class MetadataManager { model: TModel, metadata: MetadataMapList ) { + const existingMetadata = this._metadataMap.get(model) || []; + const existingProtoMetadata = Object.getPrototypeOf(model) + ? this._metadataMap.get(Object.getPrototypeOf(model)) || [] + : []; + this._metadataMap.set(model, [ - ...(this._metadataMap.has(model) ? this.getMetadata(model) : []), + ...existingProtoMetadata, + ...existingMetadata, ...metadata, ]); } diff --git a/test/metadata-manager.test.ts b/test/metadata-manager.test.ts index 12477fcfa..15b0a2e34 100644 --- a/test/metadata-manager.test.ts +++ b/test/metadata-manager.test.ts @@ -2,6 +2,13 @@ import { AutoMap } from '../src'; import { instantiate } from '../src/metadata-explorer'; describe('MetadataManager', () => { + class Base { + @AutoMap() + createdAt!: Date; + @AutoMap() + updatedAt!: Date; + } + class Address { @AutoMap() street!: string; @@ -11,7 +18,7 @@ describe('MetadataManager', () => { state!: string; } - class User { + class User extends Base { @AutoMap() firstName!: string; @AutoMap()