generated from VilledeMontreal/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: update packages and node version (major)
Signed-off-by: Matthieu <matthieu.perrin@montreal.ca>
- Loading branch information
Showing
10 changed files
with
16,612 additions
and
7,881 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 19 additions & 8 deletions
27
le-taxi-api-node.js/src/features/shared/taxiMongo/taxiMongo.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,39 @@ | ||
// Licensed under the AGPL-3.0 license. | ||
// See LICENSE file in the project root for full license information. | ||
import * as assert from 'assert'; | ||
import { Db, MongoClient } from 'mongodb'; | ||
import { configs } from '../../../config/configs'; | ||
import * as assert from "assert"; | ||
import { Db, MongoClient } from "mongodb"; | ||
import { configs } from "../../../config/configs"; | ||
|
||
let db: Db; | ||
|
||
let client: MongoClient; | ||
|
||
export async function connectToMongoDb() { | ||
client = await MongoClient.connect(buildMongoConnectionString(), { | ||
keepAlive: true, | ||
maxPoolSize: configs.dataSources.mongo.poolSize | ||
maxPoolSize: configs.dataSources.mongo.poolSize, | ||
}); | ||
db = client.db('vdm_txp'); | ||
db = client.db("vdm_txp"); | ||
return db; | ||
} | ||
|
||
function buildMongoConnectionString(): string { | ||
const { host1, host2, host3, port, username, password, defaultauthdb, options } = configs.dataSources.mongo; | ||
const { | ||
host1, | ||
host2, | ||
host3, | ||
port, | ||
username, | ||
password, | ||
defaultauthdb, | ||
options, | ||
} = configs.dataSources.mongo; | ||
return `mongodb://${username}:${password}@${host1}:${port},${host2}:${port},${host3}:${port}/${defaultauthdb}?${options}`; | ||
} | ||
|
||
export function getMongoDb() { | ||
assert.ok(db, `no instance of db mongo. Does connectToMongoDb() have been called ??`); | ||
assert.ok( | ||
db, | ||
`no instance of db mongo. Does connectToMongoDb() have been called ??` | ||
); | ||
return db; | ||
} |
Oops, something went wrong.