diff --git a/examples/mongodb-crud/backend/src/models/Global.ts b/examples/mongodb-crud/backend/src/models/Global.ts index 7e31c83..ff5f945 100644 --- a/examples/mongodb-crud/backend/src/models/Global.ts +++ b/examples/mongodb-crud/backend/src/models/Global.ts @@ -8,25 +8,10 @@ export class Global { static db: Db; static async init(logger?: Logger) { - this.db = await this._getMongoDb(BackConfig.mongoDb, logger); - } - - private static _getMongoDb(uri: string, logger?: Logger): Promise { - logger?.log(`Start connecting db...(${uri})`) - let promise = new Promise((rs, rj) => { - MongoClient.connect(uri, { - useUnifiedTopology: true, - }, (err, client) => { - if (err) { - logger?.error('× Failed connected db.', err) - rj(err); - } else { - logger?.log(`√ Connect db succ. (${uri})`) - rs(client.db()); - } - }) - }) - return promise; + logger?.log(`Start connecting db...`) + const client = await new MongoClient(BackConfig.mongoDb).connect(); + logger?.log(`Db connected successfully...`) + this.db = client.db(); } static collection(col: T): Collection { diff --git a/examples/mongodb-crud/backend/test/api/post.test.ts b/examples/mongodb-crud/backend/test/api/post.test.ts index f443a39..4c939c8 100644 --- a/examples/mongodb-crud/backend/test/api/post.test.ts +++ b/examples/mongodb-crud/backend/test/api/post.test.ts @@ -1,3 +1,4 @@ +import assert from 'assert'; import { HttpClient } from 'tsrpc'; import { Post } from '../../src/shared/protocols/models/Post'; import { serviceProto } from '../../src/shared/protocols/serviceProto';