Skip to content

Commit

Permalink
feat: replaced third argument for createmongooseconnection
Browse files Browse the repository at this point in the history
  • Loading branch information
prateekkathal committed Apr 11, 2024
1 parent 26a1c3d commit 320c264
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions lib/mongoose-core.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,10 @@ export class MongooseCoreModule implements OnApplicationShutdown {
await lastValueFrom(
defer(async () =>
mongooseConnectionFactory(
await this.createMongooseConnection(
uri,
mongooseOptions,
await this.createMongooseConnection(uri, mongooseOptions, {
lazyConnection,
onConnectionCreate,
),
}),
mongooseConnectionName,
),
).pipe(
Expand Down Expand Up @@ -125,8 +123,7 @@ export class MongooseCoreModule implements OnApplicationShutdown {
await this.createMongooseConnection(
uri as string,
mongooseOptions,
lazyConnection,
onConnectionCreate,
{ lazyConnection, onConnectionCreate },
),
mongooseConnectionName,
),
Expand Down Expand Up @@ -194,16 +191,18 @@ export class MongooseCoreModule implements OnApplicationShutdown {
private static async createMongooseConnection(
uri: string,
mongooseOptions: ConnectOptions,
lazyConnection?: boolean,
onConnectionCreate?: MongooseModuleOptions['onConnectionCreate'],
factoryOptions: {
lazyConnection?: boolean;
onConnectionCreate?: MongooseModuleOptions['onConnectionCreate'];
},
): Promise<Connection> {
const connection = mongoose.createConnection(uri, mongooseOptions);

if (lazyConnection) {
if (factoryOptions?.lazyConnection) {
return connection;
}

onConnectionCreate?.(connection);
factoryOptions?.onConnectionCreate?.(connection);

return connection.asPromise();
}
Expand Down

0 comments on commit 320c264

Please sign in to comment.