payservedb 1.0.0
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 +78 -0
- package/package.json +15 -0
- package/src/models/apilog.js +18 -0
- package/src/models/archivedapilog.js +18 -0
- package/src/models/archivedauditlog.js +83 -0
- package/src/models/auditlog.js +83 -0
- package/src/models/combinedUnits.js +62 -0
- package/src/models/company.js +52 -0
- package/src/models/customer.js +54 -0
- package/src/models/email.js +25 -0
- package/src/models/facility.js +39 -0
- package/src/models/facilityasset.js +25 -0
- package/src/models/message.js +39 -0
- package/src/models/module.js +21 -0
- package/src/models/refresh_token.js +23 -0
- package/src/models/sms_africastalking.js +21 -0
- package/src/models/sms_meliora.js +17 -0
- package/src/models/units.js +57 -0
- package/src/models/user.js +59 -0
package/index.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
const SMSAfricastalking = require('./src/models/sms_africastalking');
|
|
3
|
+
|
|
4
|
+
// Maintain a record of open connections for each database
|
|
5
|
+
const connections = {};
|
|
6
|
+
const url = '127.0.0.1';
|
|
7
|
+
const source = ''
|
|
8
|
+
|
|
9
|
+
// Utility function to connect to MongoDB
|
|
10
|
+
async function connectToMongoDB(dbName) {
|
|
11
|
+
try {
|
|
12
|
+
const connectionString = `mongodb://${url}/${dbName}${source}`;
|
|
13
|
+
await mongoose.connect(connectionString, {
|
|
14
|
+
useNewUrlParser: true,
|
|
15
|
+
useUnifiedTopology: true,
|
|
16
|
+
});
|
|
17
|
+
console.log('Connected to MongoDB');
|
|
18
|
+
} catch (err) {
|
|
19
|
+
console.error('Error connecting to MongoDB:', err);
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Function to switch databases dynamically
|
|
25
|
+
async function switchDB(dbName) {
|
|
26
|
+
// Check if there's already a connection to the desired database
|
|
27
|
+
if (connections[dbName]) {
|
|
28
|
+
return connections[dbName]; // Return existing connection
|
|
29
|
+
}
|
|
30
|
+
try {
|
|
31
|
+
const connectionString = `mongodb://${url}/${dbName}${source}`;
|
|
32
|
+
const dbConnection = await mongoose.createConnection(connectionString, {
|
|
33
|
+
useNewUrlParser: true,
|
|
34
|
+
useUnifiedTopology: true,
|
|
35
|
+
});
|
|
36
|
+
connections[dbName] = dbConnection; // Store the connection for reuse
|
|
37
|
+
console.log(`Switched to database: ${dbName}`);
|
|
38
|
+
return dbConnection;
|
|
39
|
+
} catch (err) {
|
|
40
|
+
console.error(`Error switching to database: ${dbName}`, err);
|
|
41
|
+
throw err;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Importing all model files (Note: models may need to be re-registered for different connections)
|
|
46
|
+
const models = {
|
|
47
|
+
User: require('./src/models/user'),
|
|
48
|
+
AuditLog: require('./src/models/auditlog'),
|
|
49
|
+
Company: require('./src/models/company'),
|
|
50
|
+
Email: require('./src/models/email'),
|
|
51
|
+
Module: require('./src/models/module'),
|
|
52
|
+
Facility: require('./src/models/facility'),
|
|
53
|
+
RefreshToken: require('./src/models/refresh_token'),
|
|
54
|
+
ApiLog: require('./src/models/apilog'),
|
|
55
|
+
ArchivedApiLog: require('./src/models/archivedapilog'),
|
|
56
|
+
ArchivedAuditLog: require('./src/models/archivedauditlog'),
|
|
57
|
+
FacilityAsset: require('./src/models/facilityasset'),
|
|
58
|
+
Unit: require('./src/models/units'),
|
|
59
|
+
CombinedUnit: require('./src/models/combinedUnits'),
|
|
60
|
+
Message: require('./src/models/message'),
|
|
61
|
+
SMSAfricastalking: require('./src/models/sms_africastalking'),
|
|
62
|
+
SMSMeliora: require('./src/models/sms_meliora')
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
// Function to get models dynamically from a specific database connection
|
|
66
|
+
async function getModelFromDB(dbConnection, modelName, schema) {
|
|
67
|
+
if (!dbConnection.models[modelName]) {
|
|
68
|
+
return dbConnection.model(modelName, schema); // Register the model in the db connection
|
|
69
|
+
}
|
|
70
|
+
return dbConnection.models[modelName]; // Return existing model if already registered
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
module.exports = {
|
|
74
|
+
connectToMongoDB,
|
|
75
|
+
switchDB,
|
|
76
|
+
getModelFromDB,
|
|
77
|
+
...models // Spread operator to export all models
|
|
78
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "payservedb",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
7
|
+
},
|
|
8
|
+
"keywords": [],
|
|
9
|
+
"author": "",
|
|
10
|
+
"license": "ISC",
|
|
11
|
+
"description": "",
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"mongoose": "^8.3.5"
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
// models/apiLog.js
|
|
2
|
+
const mongoose = require('mongoose');
|
|
3
|
+
const { Schema } = mongoose;
|
|
4
|
+
|
|
5
|
+
const apiLogSchema = new Schema({
|
|
6
|
+
url: { type: String, required: true, index: true },
|
|
7
|
+
method: { type: String, required: true, enum: ['GET', 'POST', 'PUT', 'DELETE'], index: true },
|
|
8
|
+
duration: { type: Number, required: true },
|
|
9
|
+
time: { type: Date, default: Date.now, required: true, index: true },
|
|
10
|
+
date: { type: String, required: true, index: true },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
apiLogSchema.index({ time: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 365 });
|
|
15
|
+
|
|
16
|
+
const ApiLog = mongoose.model('ApiLog', apiLogSchema);
|
|
17
|
+
|
|
18
|
+
module.exports = ApiLog;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
const mongoose = require('mongoose');
|
|
3
|
+
const { Schema } = mongoose;
|
|
4
|
+
|
|
5
|
+
const ArchivedApiLogSchema = new Schema({
|
|
6
|
+
url: { type: String, required: true, index: true },
|
|
7
|
+
method: { type: String, required: true, enum: ['GET', 'POST', 'PUT', 'DELETE'], index: true },
|
|
8
|
+
duration: { type: Number, required: true },
|
|
9
|
+
time: { type: Date, default: Date.now, required: true, index: true },
|
|
10
|
+
date: { type: String, required: true, index: true },
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
ArchivedApiLogSchema.index({ time: 1 }, { expireAfterSeconds: 60 * 60 * 24 * 365 });
|
|
15
|
+
|
|
16
|
+
const ArchivedApiLog = mongoose.model('ArchivedApiLog', ArchivedApiLogSchema);
|
|
17
|
+
|
|
18
|
+
module.exports = ArchivedApiLog;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const ArchivedAuditLogSchema = new mongoose.Schema({
|
|
4
|
+
action: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: true,
|
|
7
|
+
trim: true
|
|
8
|
+
},
|
|
9
|
+
page: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
trim: true
|
|
13
|
+
},
|
|
14
|
+
userId: {
|
|
15
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
16
|
+
ref: 'Company',
|
|
17
|
+
required: true
|
|
18
|
+
},
|
|
19
|
+
userInfo: {
|
|
20
|
+
type: mongoose.Schema.Types.Mixed,
|
|
21
|
+
required: true
|
|
22
|
+
},
|
|
23
|
+
projectId: {
|
|
24
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
25
|
+
ref: 'Project',
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
projectInfo: {
|
|
29
|
+
type: mongoose.Schema.Types.Mixed,
|
|
30
|
+
required: true
|
|
31
|
+
},
|
|
32
|
+
computerName: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: true,
|
|
35
|
+
trim: true
|
|
36
|
+
},
|
|
37
|
+
browser: {
|
|
38
|
+
type: String,
|
|
39
|
+
required: true,
|
|
40
|
+
trim: true
|
|
41
|
+
},
|
|
42
|
+
ipAddress: {
|
|
43
|
+
type: String,
|
|
44
|
+
required: true,
|
|
45
|
+
trim: true
|
|
46
|
+
},
|
|
47
|
+
time: {
|
|
48
|
+
type: String,
|
|
49
|
+
required: true,
|
|
50
|
+
trim: true
|
|
51
|
+
},
|
|
52
|
+
date: {
|
|
53
|
+
type: String,
|
|
54
|
+
required: true,
|
|
55
|
+
trim: true
|
|
56
|
+
},
|
|
57
|
+
createdOn: {
|
|
58
|
+
type: Date,
|
|
59
|
+
default: Date.now,
|
|
60
|
+
required: true
|
|
61
|
+
},
|
|
62
|
+
oldData: {
|
|
63
|
+
type: mongoose.Schema.Types.Mixed,
|
|
64
|
+
default: {}
|
|
65
|
+
},
|
|
66
|
+
newData: {
|
|
67
|
+
type: mongoose.Schema.Types.Mixed,
|
|
68
|
+
default: {}
|
|
69
|
+
},
|
|
70
|
+
deletedData: {
|
|
71
|
+
type: mongoose.Schema.Types.Mixed,
|
|
72
|
+
default: {}
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
timestamps: true
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
ArchivedAuditLogSchema.index({ userId: 1, projectId: 1, createdOn: -1 });
|
|
79
|
+
ArchivedAuditLogSchema.index({ action: 1 });
|
|
80
|
+
ArchivedAuditLogSchema.index({ page: 1 });
|
|
81
|
+
const ArchivedAuditLog = mongoose.model('ArchivedAuditLog', ArchivedAuditLogSchema);
|
|
82
|
+
|
|
83
|
+
module.exports = ArchivedAuditLog;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const auditLogSchema = new mongoose.Schema({
|
|
4
|
+
action: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: true,
|
|
7
|
+
trim: true
|
|
8
|
+
},
|
|
9
|
+
page: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
trim: true
|
|
13
|
+
},
|
|
14
|
+
userId: {
|
|
15
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
16
|
+
ref: 'Company',
|
|
17
|
+
required: true
|
|
18
|
+
},
|
|
19
|
+
userInfo: {
|
|
20
|
+
type: mongoose.Schema.Types.Mixed,
|
|
21
|
+
required: true
|
|
22
|
+
},
|
|
23
|
+
projectId: {
|
|
24
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
25
|
+
ref: 'Project',
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
projectInfo: {
|
|
29
|
+
type: mongoose.Schema.Types.Mixed,
|
|
30
|
+
required: true
|
|
31
|
+
},
|
|
32
|
+
computerName: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: true,
|
|
35
|
+
trim: true
|
|
36
|
+
},
|
|
37
|
+
browser: {
|
|
38
|
+
type: String,
|
|
39
|
+
required: true,
|
|
40
|
+
trim: true
|
|
41
|
+
},
|
|
42
|
+
ipAddress: {
|
|
43
|
+
type: String,
|
|
44
|
+
required: true,
|
|
45
|
+
trim: true
|
|
46
|
+
},
|
|
47
|
+
time: {
|
|
48
|
+
type: String,
|
|
49
|
+
required: true,
|
|
50
|
+
trim: true
|
|
51
|
+
},
|
|
52
|
+
date: {
|
|
53
|
+
type: String,
|
|
54
|
+
required: true,
|
|
55
|
+
trim: true
|
|
56
|
+
},
|
|
57
|
+
createdOn: {
|
|
58
|
+
type: Date,
|
|
59
|
+
default: Date.now,
|
|
60
|
+
required: true
|
|
61
|
+
},
|
|
62
|
+
oldData: {
|
|
63
|
+
type: mongoose.Schema.Types.Mixed,
|
|
64
|
+
default: {}
|
|
65
|
+
},
|
|
66
|
+
newData: {
|
|
67
|
+
type: mongoose.Schema.Types.Mixed,
|
|
68
|
+
default: {}
|
|
69
|
+
},
|
|
70
|
+
deletedData: {
|
|
71
|
+
type: mongoose.Schema.Types.Mixed,
|
|
72
|
+
default: {}
|
|
73
|
+
}
|
|
74
|
+
}, {
|
|
75
|
+
timestamps: true
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
auditLogSchema.index({ userId: 1, projectId: 1, createdOn: -1 });
|
|
79
|
+
auditLogSchema.index({ action: 1 });
|
|
80
|
+
auditLogSchema.index({ page: 1 });
|
|
81
|
+
const AuditLog = mongoose.model('AuditLog', auditLogSchema);
|
|
82
|
+
|
|
83
|
+
module.exports = AuditLog;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
// Define the schema for companies
|
|
4
|
+
const combinedUnitSchema = new mongoose.Schema({
|
|
5
|
+
combinedUnitName: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true
|
|
8
|
+
},
|
|
9
|
+
combinedDivision:{
|
|
10
|
+
type:String,
|
|
11
|
+
required:true
|
|
12
|
+
},
|
|
13
|
+
combinedUnitType:{
|
|
14
|
+
type:String,
|
|
15
|
+
required:true
|
|
16
|
+
},
|
|
17
|
+
combinedFloorUnit:{
|
|
18
|
+
type:String,
|
|
19
|
+
required:true
|
|
20
|
+
},
|
|
21
|
+
combinedLettableFloorArea:{
|
|
22
|
+
type:String,
|
|
23
|
+
required:false
|
|
24
|
+
},
|
|
25
|
+
combinedLRNumber:{
|
|
26
|
+
type:String,
|
|
27
|
+
required:true
|
|
28
|
+
},
|
|
29
|
+
combinedGrossArea:{
|
|
30
|
+
type:Number,
|
|
31
|
+
required:false
|
|
32
|
+
},
|
|
33
|
+
combinedNetLettableArea:{
|
|
34
|
+
type:Number,
|
|
35
|
+
required:false
|
|
36
|
+
},
|
|
37
|
+
combinedReason:{
|
|
38
|
+
type:String,
|
|
39
|
+
required:false
|
|
40
|
+
},
|
|
41
|
+
status:{
|
|
42
|
+
type:String,
|
|
43
|
+
required:true
|
|
44
|
+
},
|
|
45
|
+
selectedCombinedUnits:[],
|
|
46
|
+
facilityId:{
|
|
47
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
48
|
+
ref: 'Facility',
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
}, {
|
|
53
|
+
timestamps: true // Automatically add createdAt and updatedAt fields
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// Indexes for improved performance
|
|
57
|
+
combinedUnitSchema.index({ name: 1 });
|
|
58
|
+
|
|
59
|
+
// Compile the model from the schema
|
|
60
|
+
const CombinedUnit = mongoose.model('CombinedUnit', combinedUnitSchema);
|
|
61
|
+
|
|
62
|
+
module.exports = CombinedUnit;
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
// Define the schema for companies
|
|
4
|
+
const companySchema = new mongoose.Schema({
|
|
5
|
+
name: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: [true, 'Company name is required'],
|
|
8
|
+
trim: true,
|
|
9
|
+
minlength: [1, 'Company name must be at least 1 character long']
|
|
10
|
+
},
|
|
11
|
+
address: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: false
|
|
14
|
+
},
|
|
15
|
+
country: { type: String, required: false },
|
|
16
|
+
email: { type: String, required: true },
|
|
17
|
+
city: { type: String, required: true },
|
|
18
|
+
registrationNumber:{ type: String, required: true },
|
|
19
|
+
companyTaxNumber:{type:String,required:true},
|
|
20
|
+
logo: {
|
|
21
|
+
type: String,
|
|
22
|
+
trim: false,
|
|
23
|
+
default: null
|
|
24
|
+
},
|
|
25
|
+
isEnabled: { type: Boolean, default: false },
|
|
26
|
+
kyc: {
|
|
27
|
+
taxCertificate: {
|
|
28
|
+
type: String
|
|
29
|
+
},
|
|
30
|
+
Id: {
|
|
31
|
+
type: String
|
|
32
|
+
},
|
|
33
|
+
companyCertificate: {
|
|
34
|
+
type: String
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
|
|
38
|
+
facilities: [{
|
|
39
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
40
|
+
ref: 'Facility'
|
|
41
|
+
}]
|
|
42
|
+
}, {
|
|
43
|
+
timestamps: true // Automatically add createdAt and updatedAt fields
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Indexes for improved performance
|
|
47
|
+
companySchema.index({ name: 1 });
|
|
48
|
+
|
|
49
|
+
// Compile the model from the schema
|
|
50
|
+
const Company = mongoose.model('Company', companySchema);
|
|
51
|
+
|
|
52
|
+
module.exports = Company;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
// Define the schema for customers
|
|
4
|
+
const customerSchema = new mongoose.Schema({
|
|
5
|
+
customerNumber: {
|
|
6
|
+
type: Number,
|
|
7
|
+
required: [true, 'Customer number is required'],
|
|
8
|
+
unique: true // Ensure customer number is unique
|
|
9
|
+
},
|
|
10
|
+
firstName: {
|
|
11
|
+
type: String,
|
|
12
|
+
required: [true, 'First name is required'],
|
|
13
|
+
trim: true
|
|
14
|
+
},
|
|
15
|
+
lastName: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: [true, 'Last name is required'],
|
|
18
|
+
trim: true
|
|
19
|
+
},
|
|
20
|
+
email: {
|
|
21
|
+
type: String,
|
|
22
|
+
required: [true, 'Email is required'],
|
|
23
|
+
unique: true, // Ensure email uniqueness for data integrity
|
|
24
|
+
lowercase: true, // Normalize email to lowercase
|
|
25
|
+
trim: true,
|
|
26
|
+
match: [/\S+@\S+\.\S+/, 'Email format is invalid'] // Validate email format
|
|
27
|
+
},
|
|
28
|
+
phoneNumber: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: [true, 'Phone number is required'],
|
|
31
|
+
trim: true
|
|
32
|
+
},
|
|
33
|
+
type: {
|
|
34
|
+
type: String,
|
|
35
|
+
required: [true, 'Type is required'],
|
|
36
|
+
enum: ['Tenant', 'Home Owner'],
|
|
37
|
+
},
|
|
38
|
+
projectId: {
|
|
39
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
40
|
+
ref: 'Project',
|
|
41
|
+
required: [true, 'Project ID is required']
|
|
42
|
+
}
|
|
43
|
+
}, {
|
|
44
|
+
timestamps: true // Automatically add createdAt and updatedAt fields
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
// Indexes for improved performance
|
|
48
|
+
customerSchema.index({ email: 1 });
|
|
49
|
+
customerSchema.index({ customerNumber: 1 });
|
|
50
|
+
|
|
51
|
+
// Compile the model from the schema
|
|
52
|
+
const Customer = mongoose.model('Customer', customerSchema);
|
|
53
|
+
|
|
54
|
+
module.exports = Customer;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
const EmailSchema = mongoose.Schema({
|
|
3
|
+
user: {
|
|
4
|
+
type: String,
|
|
5
|
+
required: true
|
|
6
|
+
},
|
|
7
|
+
from: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true
|
|
10
|
+
},
|
|
11
|
+
host: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true
|
|
14
|
+
},
|
|
15
|
+
port: {
|
|
16
|
+
type: Number,
|
|
17
|
+
required: true
|
|
18
|
+
},
|
|
19
|
+
auth: {
|
|
20
|
+
user: String,
|
|
21
|
+
pass: String
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
const Email = mongoose.model('Email', EmailSchema);
|
|
25
|
+
module.exports = Email
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
// Define the schema for companies
|
|
4
|
+
const facilitySchema = new mongoose.Schema({
|
|
5
|
+
name: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: [true, 'Facility name is required'],
|
|
8
|
+
trim: true,
|
|
9
|
+
minlength: [1, 'Facility name must be at least 1 character long']
|
|
10
|
+
},
|
|
11
|
+
location:{
|
|
12
|
+
type:String,
|
|
13
|
+
required:true
|
|
14
|
+
},
|
|
15
|
+
subDivision:{type:String,required:true},
|
|
16
|
+
isEnabled:{type:Boolean,required:true},
|
|
17
|
+
divisionArray:[],
|
|
18
|
+
landReferenceNumbers:[],
|
|
19
|
+
defaultMeasurement:{type:String,required:false},
|
|
20
|
+
totalCommonArea:{type:String,required:false},
|
|
21
|
+
totalLettableArea:{type:String,required:false},
|
|
22
|
+
|
|
23
|
+
logo: {
|
|
24
|
+
type: String,
|
|
25
|
+
trim: false,
|
|
26
|
+
default: null
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}, {
|
|
30
|
+
timestamps: true // Automatically add createdAt and updatedAt fields
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
// Indexes for improved performance
|
|
34
|
+
facilitySchema.index({ name: 1 });
|
|
35
|
+
|
|
36
|
+
// Compile the model from the schema
|
|
37
|
+
const Facility = mongoose.model('Facility', facilitySchema);
|
|
38
|
+
|
|
39
|
+
module.exports = Facility;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
// Define the schema for companies
|
|
4
|
+
const facilityassetSchema = new mongoose.Schema({
|
|
5
|
+
name: {
|
|
6
|
+
type: String,
|
|
7
|
+
required:true
|
|
8
|
+
},
|
|
9
|
+
facilityId:{
|
|
10
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
11
|
+
ref: 'Facility',
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
}, {
|
|
16
|
+
timestamps: true // Automatically add createdAt and updatedAt fields
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
// Indexes for improved performance
|
|
20
|
+
facilityassetSchema.index({ name: 1 });
|
|
21
|
+
|
|
22
|
+
// Compile the model from the schema
|
|
23
|
+
const FacilityAsset = mongoose.model('FacilityAsset', facilityassetSchema);
|
|
24
|
+
|
|
25
|
+
module.exports = FacilityAsset;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
const MessageSchema = mongoose.Schema({
|
|
3
|
+
type: {
|
|
4
|
+
type: String,
|
|
5
|
+
required: true
|
|
6
|
+
},
|
|
7
|
+
recipient: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true,
|
|
10
|
+
},
|
|
11
|
+
subject: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: false
|
|
14
|
+
},
|
|
15
|
+
body: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: true
|
|
18
|
+
},
|
|
19
|
+
sentOn: {
|
|
20
|
+
type: Date,
|
|
21
|
+
required: false
|
|
22
|
+
},
|
|
23
|
+
createdOn:{
|
|
24
|
+
type:Date,
|
|
25
|
+
required:true
|
|
26
|
+
},
|
|
27
|
+
status: {
|
|
28
|
+
type: String,
|
|
29
|
+
required: true,
|
|
30
|
+
enum: ['Not Sent', 'In Queue', 'Sent']
|
|
31
|
+
},
|
|
32
|
+
messageId: {
|
|
33
|
+
type: String,
|
|
34
|
+
required: false
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
})
|
|
38
|
+
const Message = mongoose.model('Message', MessageSchema);
|
|
39
|
+
module.exports = Message
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
// Define the schema for modules
|
|
4
|
+
const moduleSchema = new mongoose.Schema({
|
|
5
|
+
name: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: [true, 'Module name is required'],
|
|
8
|
+
trim: true,
|
|
9
|
+
unique: true // Ensure module name is unique
|
|
10
|
+
}
|
|
11
|
+
}, {
|
|
12
|
+
timestamps: true // Automatically add createdAt and updatedAt fields
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// Indexes for improved performance
|
|
16
|
+
moduleSchema.index({ name: 1 });
|
|
17
|
+
|
|
18
|
+
// Compile the model from the schema
|
|
19
|
+
const Module = mongoose.model('Module', moduleSchema);
|
|
20
|
+
|
|
21
|
+
module.exports = Module;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const refreshTokenSchema = new mongoose.Schema({
|
|
4
|
+
userId: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: true,
|
|
7
|
+
index: true, // Index for faster lookup by userId
|
|
8
|
+
},
|
|
9
|
+
token: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: true,
|
|
12
|
+
},
|
|
13
|
+
createdAt: {
|
|
14
|
+
type: Date,
|
|
15
|
+
required: true,
|
|
16
|
+
default: Date.now,
|
|
17
|
+
expires: '30d', // Example: Token expires after 30 days
|
|
18
|
+
},
|
|
19
|
+
},{timestamps: true});
|
|
20
|
+
|
|
21
|
+
const RefreshToken = mongoose.model('RefreshToken', refreshTokenSchema);
|
|
22
|
+
|
|
23
|
+
module.exports = RefreshToken;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
const SMSAfricastalkingSchema = mongoose.Schema({
|
|
3
|
+
user: {
|
|
4
|
+
type: String,
|
|
5
|
+
required: true
|
|
6
|
+
},
|
|
7
|
+
senderId: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true
|
|
10
|
+
},
|
|
11
|
+
userName: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true,
|
|
14
|
+
},
|
|
15
|
+
apiKey: {
|
|
16
|
+
type: String,
|
|
17
|
+
required: true
|
|
18
|
+
}
|
|
19
|
+
})
|
|
20
|
+
const SMSAfricastalking = mongoose.model('SMSAfricastalking', SMSAfricastalkingSchema);
|
|
21
|
+
module.exports = SMSAfricastalking
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
const SMSMelioraSchema = mongoose.Schema({
|
|
3
|
+
user: {
|
|
4
|
+
type: String,
|
|
5
|
+
required: true
|
|
6
|
+
},
|
|
7
|
+
senderId: {
|
|
8
|
+
type: String,
|
|
9
|
+
required: true
|
|
10
|
+
},
|
|
11
|
+
apiKey: {
|
|
12
|
+
type: String,
|
|
13
|
+
required: true
|
|
14
|
+
}
|
|
15
|
+
})
|
|
16
|
+
const SMSMeliora = mongoose.model('SMSMeliora', SMSMelioraSchema);
|
|
17
|
+
module.exports = SMSMeliora
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
// Define the schema for companies
|
|
4
|
+
const unitSchema = new mongoose.Schema({
|
|
5
|
+
name: {
|
|
6
|
+
type: String,
|
|
7
|
+
required: true
|
|
8
|
+
},
|
|
9
|
+
unitType:{
|
|
10
|
+
type:String,
|
|
11
|
+
required:true
|
|
12
|
+
},
|
|
13
|
+
division:{
|
|
14
|
+
type:String,
|
|
15
|
+
required:true
|
|
16
|
+
},
|
|
17
|
+
floorUnitNo:{
|
|
18
|
+
type:String,
|
|
19
|
+
required:true
|
|
20
|
+
},
|
|
21
|
+
lettableFloorArea:{
|
|
22
|
+
type:String,
|
|
23
|
+
required:false
|
|
24
|
+
},
|
|
25
|
+
landRateNumber:{
|
|
26
|
+
type:String,
|
|
27
|
+
required:false
|
|
28
|
+
},
|
|
29
|
+
grossArea:{
|
|
30
|
+
type:Number,
|
|
31
|
+
required:false
|
|
32
|
+
},
|
|
33
|
+
netLettableArea:{
|
|
34
|
+
type:Number,
|
|
35
|
+
required:false
|
|
36
|
+
},
|
|
37
|
+
status:{
|
|
38
|
+
type:String,
|
|
39
|
+
required:true
|
|
40
|
+
},
|
|
41
|
+
facilityId:{
|
|
42
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
43
|
+
ref: 'Facility',
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
}, {
|
|
48
|
+
timestamps: true // Automatically add createdAt and updatedAt fields
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
// Indexes for improved performance
|
|
52
|
+
unitSchema.index({ name: 1 });
|
|
53
|
+
|
|
54
|
+
// Compile the model from the schema
|
|
55
|
+
const Unit = mongoose.model('Unit', unitSchema);
|
|
56
|
+
|
|
57
|
+
module.exports = Unit;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const userSchema = new mongoose.Schema({
|
|
4
|
+
fullName: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: [true, 'Full name is required'],
|
|
7
|
+
trim: true,
|
|
8
|
+
},
|
|
9
|
+
email: {
|
|
10
|
+
type: String,
|
|
11
|
+
required: [true, 'Email is required'],
|
|
12
|
+
unique: true,
|
|
13
|
+
lowercase: true,
|
|
14
|
+
trim: true,
|
|
15
|
+
},
|
|
16
|
+
phoneNumber: {
|
|
17
|
+
type: String,
|
|
18
|
+
required: false,
|
|
19
|
+
trim: true,
|
|
20
|
+
},
|
|
21
|
+
idNumber:{
|
|
22
|
+
type:String,
|
|
23
|
+
required:false
|
|
24
|
+
},
|
|
25
|
+
type: {
|
|
26
|
+
type: String,
|
|
27
|
+
required: [true, 'Type is required'],
|
|
28
|
+
enum: ['Company', 'Project Manager', 'Universal', 'Core', 'Customer'],
|
|
29
|
+
},
|
|
30
|
+
role: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: [true, 'Role is required'],
|
|
33
|
+
enum: ['admin', 'editor', 'user'],
|
|
34
|
+
},
|
|
35
|
+
kyc:{
|
|
36
|
+
|
|
37
|
+
Id:{
|
|
38
|
+
type:String
|
|
39
|
+
}
|
|
40
|
+
},
|
|
41
|
+
companies: [{
|
|
42
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
43
|
+
ref: 'Company',
|
|
44
|
+
}],
|
|
45
|
+
password: {
|
|
46
|
+
type: String,
|
|
47
|
+
required: [true, 'Password is required'],
|
|
48
|
+
minlength: 8,
|
|
49
|
+
},
|
|
50
|
+
}, {
|
|
51
|
+
timestamps: true, // Automatically add createdAt and updatedAt fields
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
userSchema.index({ fullName: 'text', email: 'text' });
|
|
56
|
+
|
|
57
|
+
const User = mongoose.model('User', userSchema);
|
|
58
|
+
|
|
59
|
+
module.exports = User;
|