From 6d0a2548db2cdf50f8d3591a964afa71dc010a9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20My=C5=9Bliwiec?= Date: Wed, 8 Jul 2020 13:37:26 +0200 Subject: [PATCH] fix(): fix date and map support for defs factory --- lib/factories/definitions.factory.ts | 4 ++-- lib/storages/type-metadata.storage.ts | 2 +- tests/e2e/schema-definitions.factory.spec.ts | 18 ++++++++++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/lib/factories/definitions.factory.ts b/lib/factories/definitions.factory.ts index 9d2bef81..16efdcd1 100644 --- a/lib/factories/definitions.factory.ts +++ b/lib/factories/definitions.factory.ts @@ -4,7 +4,7 @@ import * as mongoose from 'mongoose'; import { PropOptions } from '../decorators'; import { TypeMetadataStorage } from '../storages/type-metadata.storage'; -const PRIMITIVE_TYPES: Function[] = [Boolean, Number, String]; +const BUILT_IN_TYPES: Function[] = [Boolean, Number, String, Map, Date]; export class DefinitionsFactory { static createForClass(target: Type): mongoose.SchemaDefinition { @@ -62,7 +62,7 @@ export class DefinitionsFactory { } private static isPrimitive(type: Function) { - return PRIMITIVE_TYPES.includes(type); + return BUILT_IN_TYPES.includes(type); } private static isMongooseSchemaType(type: Function) { diff --git a/lib/storages/type-metadata.storage.ts b/lib/storages/type-metadata.storage.ts index 448405ab..22979a5f 100644 --- a/lib/storages/type-metadata.storage.ts +++ b/lib/storages/type-metadata.storage.ts @@ -17,7 +17,7 @@ export class TypeMetadataStorageHost { } getSchemaMetadataByTarget(target: Type): SchemaMetadata | undefined { - return this.schemas.find(item => item.target === target); + return this.schemas.find((item) => item.target === target); } private compileClassMetadata(metadata: SchemaMetadata) { diff --git a/tests/e2e/schema-definitions.factory.spec.ts b/tests/e2e/schema-definitions.factory.spec.ts index 8d8619ef..c20c045e 100644 --- a/tests/e2e/schema-definitions.factory.spec.ts +++ b/tests/e2e/schema-definitions.factory.spec.ts @@ -27,6 +27,17 @@ class ExampleClass { @Prop() mixed: mongoose.Schema.Types.Mixed; + @Prop( + raw({ + expires: 0, + type: Date, + }), + ) + expiresAt: Date; + + @Prop() + map: Map; + @Prop() isEnabled: boolean; @@ -90,9 +101,16 @@ describe('DefinitionsFactory', () => { array: { type: [] }, customArray: [{ custom: 'literal', object: true }], customObject: { custom: 'literal', object: true }, + expiresAt: { + expires: 0, + type: Date, + }, isEnabled: { type: Boolean, }, + map: { + type: Map, + }, mixed: { type: mongoose.Schema.Types.Mixed }, number: { type: Number }, });