import * as mongoose from 'mongoose' ; import { MongooseConnectionToken } from './mongoose.constants' ; import { MongooseModuleConfig } from './mongoose.interfaces' ; export function createMongooseModuleProviders ( config ) { const mongooseProvider = { provide : MongooseConnectionToken , useFactory : async ( ) => mongoose . connect ( config . uris , config . options ) } ; const modelsProvider = ( config . models || [ ] ) . map ( model => ( { provide : model . inject , useFactory : connection => connection . model ( model . name , model . schema ) , inject : [ MongooseConnectionToken ] } ) ) ; return [ mongooseProvider , ... modelsProvider ] ; }