Skip to content

Commit

Permalink
feat: use virtuals factory in schema factory
Browse files Browse the repository at this point in the history
  • Loading branch information
LotfiMEZIANI committed May 22, 2022
1 parent 1bbf2e6 commit de9b3fb
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/factories/schema.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as mongoose from 'mongoose';
import { SchemaDefinition, SchemaDefinitionType } from 'mongoose';
import { TypeMetadataStorage } from '../storages/type-metadata.storage';
import { DefinitionsFactory } from './definitions.factory';
import { VirtualsFactory } from './virtuals.factory';

export class SchemaFactory {
// TODO: remove unused, deprecated type argument
Expand All @@ -13,9 +14,13 @@ export class SchemaFactory {
const schemaDefinition = DefinitionsFactory.createForClass(target);
const schemaMetadata =
TypeMetadataStorage.getSchemaMetadataByTarget(target);
return new mongoose.Schema<TClass>(
const schema = new mongoose.Schema<TClass>(
schemaDefinition as SchemaDefinition<SchemaDefinitionType<TClass>>,
schemaMetadata && schemaMetadata.options,
);

VirtualsFactory.createForClass(target, schema);

return schema;
}
}

0 comments on commit de9b3fb

Please sign in to comment.