payservedb 2.7.5 → 2.7.7

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
@@ -4,24 +4,36 @@ require('dotenv').config()
4
4
 
5
5
  // Maintain a record of open connections for each database
6
6
  const connections = {};
7
- const url = '127.0.0.1:27017';
8
- const source = '?authSource=admin'
7
+
9
8
 
10
9
  // Utility function to connect to MongoDB
11
- async function connectToMongoDB(dbName) {
10
+ async function connectToMongoDB(dbName, secured, username, password, url, port) {
12
11
  try {
13
-
14
- const connectionString = `mongodb://${url}/${dbName}${source}`;
15
- await mongoose.connect(connectionString, {
16
- useNewUrlParser: true,
17
- });
18
- console.log('Connected to MongoDB');
12
+ if (!secured) {
13
+ const url_ = url + ":" + port;
14
+ const connectionString = `mongodb://${url_}/${dbName}`;
15
+ await mongoose.connect(connectionString, {
16
+ useNewUrlParser: true,
17
+ });
18
+ console.log('Connected to MongoDB');
19
+ }
20
+ else {
21
+ const url_ = `${username}:${password}@${url}${port}`;
22
+ const source = '?authSource=admin'
23
+ const connectionString = `mongodb://${url_}/${dbName}${source}`;
24
+ await mongoose.connect(connectionString, {
25
+ useNewUrlParser: true,
26
+ });
27
+ console.log('Connected to MongoDB');
28
+ }
29
+
19
30
  } catch (err) {
20
31
  console.error('Error connecting to MongoDB:', err);
21
32
  throw err;
22
33
  }
23
34
  }
24
35
 
36
+
25
37
  // Function to switch databases dynamically
26
38
  async function switchDB(dbName) {
27
39
  // Check if there's already a connection to the desired database
@@ -89,7 +101,12 @@ const models = {
89
101
  Requisition:require('./src/models/maintenancerequisition'),
90
102
  LeaseAgreement:require('./src/models/leaseagreement'),
91
103
  WorkOrder:require('./src/models/workorder'),
92
- ServiceInvoice:require('./src/models/service_invoice')
104
+ ServiceInvoice:require('./src/models/service_invoice'),
105
+ ValueAddedService:require('./src/models/valueaddedservices'),
106
+ VasInvoice:require('./src/models/vasinvoice'),
107
+ VasVendor:require('./src/models/vasvendor'),
108
+ ServiceRequest:require('./src/models/servicerequest'),
109
+ Employee:require('./src/models/employees')
93
110
 
94
111
  };
95
112
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "2.7.5",
3
+ "version": "2.7.7",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -0,0 +1,33 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Define the Employee schema
4
+ const employeeSchema = new mongoose.Schema({
5
+ facilityId: {
6
+ type: mongoose.Schema.Types.ObjectId,
7
+ ref: 'Facility',
8
+ required: true,
9
+ },
10
+ name: {
11
+ type: String,
12
+ required: true,
13
+ },
14
+ contact: {
15
+ type: String,
16
+ required: true,
17
+ },
18
+ phoneNumber: {
19
+ type: String,
20
+ required: true,
21
+ },
22
+ service: [{
23
+ type: mongoose.Schema.Types.ObjectId,
24
+ ref: 'ValueAddedService',
25
+ required: true,
26
+ }],
27
+ }, {
28
+ timestamps: true,
29
+ });
30
+
31
+ const Employee = mongoose.model('Employee', employeeSchema);
32
+
33
+ module.exports = { Employee };
@@ -0,0 +1,55 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Define the schema for ServiceRequests
4
+ const serviceRequestSchema = new mongoose.Schema({
5
+ facilityId: {
6
+ type: Number,
7
+ required: true
8
+ },
9
+ date: {
10
+ type: Date,
11
+ required: true
12
+ },
13
+ time: {
14
+ type: String,
15
+ required: true
16
+ },
17
+ serviceId: {
18
+ type: Number,
19
+ required: true
20
+ },
21
+ status: {
22
+ type: String,
23
+ required: true,
24
+ enum: ['Pending', 'In Progress', 'Completed', 'Cancelled'],
25
+ },
26
+ customerId: {
27
+ type: Number,
28
+ required: true
29
+ },
30
+ // Fields for commission-related services (appears when isCommissionSelected is true)
31
+ frequency: {
32
+ type: String,
33
+ enum: ['Daily', 'Weekly', 'Monthly'],
34
+ required: function () {
35
+ return this.isCommissionSelected;
36
+ }
37
+ },
38
+ percentage: {
39
+ type: Number,
40
+ required: function () {
41
+ return this.isCommissionSelected;
42
+ }
43
+ },
44
+ // Fields for non-commission-related services
45
+ isCommissionSelected: {
46
+ type: Boolean,
47
+ default: false
48
+ }
49
+ }, {
50
+ timestamps: true
51
+ });
52
+
53
+ const ServiceRequest = mongoose.model('ServiceRequest', serviceRequestSchema);
54
+
55
+ module.exports = ServiceRequest;
@@ -44,6 +44,37 @@ const ticketSchema = new mongoose.Schema({
44
44
  ticketNumber: {
45
45
  type: Number,
46
46
  },
47
+ needsFix: {
48
+ type: String,
49
+ required: true,
50
+ },
51
+ byWho: {
52
+ type: String,
53
+ required: false,
54
+ },
55
+ selectedEmployee: {
56
+ type: String,
57
+ required: false,
58
+ },
59
+ selectedVendor: {
60
+ type: String,
61
+ required: false,
62
+ },
63
+ assessImage: {
64
+ type: String,
65
+ },
66
+ reviewText: {
67
+ type: String,
68
+ required: false,
69
+ },
70
+ amount: {
71
+ type: Number,
72
+ required: false,
73
+ },
74
+ payer: {
75
+ type: String,
76
+ required: false,
77
+ },
47
78
  }, {
48
79
  timestamps: true,
49
80
  });
@@ -0,0 +1,21 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Define the schema for ValueAddedServices
4
+ const valueAddedServiceSchema = new mongoose.Schema({
5
+ facilityId: {
6
+ type: mongoose.Schema.Types.ObjectId,
7
+ ref: 'Facility',
8
+ required: true
9
+ },
10
+ serviceName: {
11
+ type: String,
12
+ required: true,
13
+ trim: true
14
+ }
15
+ }, {
16
+ timestamps: true
17
+ });
18
+
19
+ const ValueAddedService = mongoose.model('ValueAddedService', valueAddedServiceSchema);
20
+
21
+ module.exports = ValueAddedService;
@@ -0,0 +1,42 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Define the schema for VasInvoices
4
+ const vasInvoiceSchema = new mongoose.Schema({
5
+ facilityId: {
6
+ type: Number,
7
+ required: true
8
+ },
9
+ serviceId: {
10
+ type: Number,
11
+ required: true
12
+ },
13
+ serviceVendorId: {
14
+ type: Number
15
+ },
16
+ customerId: {
17
+ type: Number,
18
+ required: true
19
+ },
20
+ status: {
21
+ type: String,
22
+ required: true,
23
+ enum: ['Pending', 'Paid', 'Cancelled', 'Overdue'], // Example of possible statuses, can be adjusted as needed
24
+ },
25
+ time: {
26
+ type: String,
27
+ required: true
28
+ },
29
+ date: {
30
+ type: Date,
31
+ required: true
32
+ },
33
+ amount: {
34
+ type: Number
35
+ }
36
+ }, {
37
+ timestamps: true
38
+ });
39
+
40
+ const VasInvoice = mongoose.model('VasInvoice', vasInvoiceSchema);
41
+
42
+ module.exports = VasInvoice;
@@ -0,0 +1,53 @@
1
+ const mongoose = require('mongoose');
2
+
3
+ // Define the schema for VasVendor
4
+ const vasVendorSchema = new mongoose.Schema({
5
+ name: {
6
+ type: String,
7
+ required: true,
8
+ trim: true
9
+ },
10
+ location: {
11
+ type: String,
12
+ required: true,
13
+ trim: true
14
+ },
15
+ jobDescription: {
16
+ type: String,
17
+ required: true,
18
+ trim: true
19
+ },
20
+ offers: [{
21
+ serviceId: {
22
+ type: mongoose.Schema.Types.ObjectId,
23
+ ref: 'Service', // Reference to the Service model
24
+ required: true
25
+ },
26
+ amount: {
27
+ type: Number,
28
+ required: true,
29
+ min: [0, 'Amount must be a positive number']
30
+ }
31
+ }],
32
+ contactDetails: {
33
+ name: {
34
+ type: String,
35
+ required: true
36
+ },
37
+ phone: {
38
+ type: String,
39
+ required: true
40
+ },
41
+ email: {
42
+ type: String,
43
+ required: true,
44
+ match: [/.+\@.+\..+/, 'Please provide a valid email address']
45
+ }
46
+ }
47
+ }, {
48
+ timestamps: true // This will automatically add createdAt and updatedAt fields
49
+ });
50
+
51
+ const VasVendor = mongoose.model('VasVendor', vasVendorSchema);
52
+
53
+ module.exports = VasVendor;