payservedb 9.9.4 → 9.9.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.js CHANGED
@@ -5,6 +5,18 @@ require("dotenv").config();
5
5
  // Maintain a record of open connections for each database
6
6
  const connections = {};
7
7
 
8
+ // Consuming services (e.g. backend_main) typically run one connection per
9
+ // cluster worker process. Without an explicit cap here, the MongoDB Node
10
+ // driver defaults maxPoolSize to 100 *per connection* — so N worker
11
+ // processes each calling connectToMongoDB() can reserve up to N*100
12
+ // sockets on the server even under light load. Capping it keeps a single
13
+ // process's footprint bounded and predictable.
14
+ const defaultMongoOptions = {
15
+ useNewUrlParser: true,
16
+ maxPoolSize: 20,
17
+ minPoolSize: 2,
18
+ };
19
+
8
20
  // Utility function to connect to MongoDB
9
21
  async function connectToMongoDB(
10
22
  dbName,
@@ -18,17 +30,13 @@ async function connectToMongoDB(
18
30
  if (secured === false) {
19
31
  const url_ = url + ":" + port;
20
32
  const connectionString = `mongodb://${url_}/${dbName}`;
21
- await mongoose.connect(connectionString, {
22
- useNewUrlParser: true,
23
- });
33
+ await mongoose.connect(connectionString, defaultMongoOptions);
24
34
  console.log("Connected to MongoDB");
25
35
  } else {
26
36
  const url_ = `${username}:${password}@${url}:${port}`;
27
37
  const source = "?authSource=admin";
28
38
  const connectionString = `mongodb://${url_}/${dbName}${source}`;
29
- await mongoose.connect(connectionString, {
30
- useNewUrlParser: true,
31
- });
39
+ await mongoose.connect(connectionString, defaultMongoOptions);
32
40
  console.log("Connected to MongoDB");
33
41
  }
34
42
  } catch (err) {
@@ -53,9 +61,7 @@ async function switchDB(dbName) {
53
61
  const source = "?authSource=admin";
54
62
 
55
63
  const connectionString = `mongodb://${username}:${password}@${url}:${port}/${dbName}${source}`;
56
- const dbConnection = await mongoose.createConnection(connectionString, {
57
- useNewUrlParser: true,
58
- });
64
+ const dbConnection = await mongoose.createConnection(connectionString, defaultMongoOptions);
59
65
 
60
66
  connections[dbName] = dbConnection; // Store the connection for reuse
61
67
  console.log(`Switched to database: ${dbName}`);
@@ -387,9 +393,7 @@ async function connectToMoveInDB(dbName, secured, username, password, url, port)
387
393
  connectionString = `mongodb://${username}:${password}@${url}:${port}/${dbName}${source}`;
388
394
  }
389
395
 
390
- const conn = await mongoose.createConnection(connectionString, {
391
- useNewUrlParser: true,
392
- });
396
+ const conn = await mongoose.createConnection(connectionString, defaultMongoOptions);
393
397
 
394
398
  console.log(`Connected to Move-In DB: ${dbName}`);
395
399
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "9.9.4",
3
+ "version": "9.9.6",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -1,33 +1,38 @@
1
1
  const mongoose = require('mongoose');
2
2
 
3
- // Define the schema for guards
3
+ // Define the schema for receptionists
4
4
  const receptionSchema = new mongoose.Schema({
5
+
5
6
  firstName: {
6
7
  type: String,
7
8
  required: true
8
9
  },
10
+
9
11
  lastName: {
10
12
  type: String,
11
13
  required: true
12
14
  },
15
+
13
16
  phoneNumber: {
14
17
  type: String,
15
18
  required: true
16
19
  },
17
- email:{
18
- type:String,
19
- required:false
20
+
21
+ email: {
22
+ type: String,
23
+ required: false
20
24
  },
25
+
21
26
  facilityId: {
22
27
  type: mongoose.Schema.Types.ObjectId,
23
28
  ref: 'Facility',
24
- required: true // Assuming facilityId is required
29
+ required: true
25
30
  }
31
+
26
32
  }, {
27
- timestamps: true // Automatically adds createdAt and updatedAt fields
33
+ timestamps: true
28
34
  });
29
35
 
30
- // Compile the model from the schema
31
36
  const Reception = mongoose.model('Reception', receptionSchema);
32
37
 
33
- module.exports = Reception;
38
+ module.exports = Reception;