payservedb 1.1.6 → 1.1.8
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 +83 -83
- package/package.json +14 -14
- package/src/models/apilog.js +18 -18
- package/src/models/archivedapilog.js +18 -18
- package/src/models/archivedauditlog.js +83 -83
- package/src/models/auditlog.js +83 -83
- package/src/models/brian.js +5 -5
- package/src/models/combinedUnits.js +62 -62
- package/src/models/company.js +52 -52
- package/src/models/customer.js +114 -76
- package/src/models/email.js +24 -24
- package/src/models/facility.js +39 -39
- package/src/models/facilityasset.js +25 -25
- package/src/models/message.js +38 -38
- package/src/models/module.js +21 -21
- package/src/models/refresh_token.js +23 -23
- package/src/models/sms_africastalking.js +20 -20
- package/src/models/sms_meliora.js +16 -16
- package/src/models/units.js +57 -57
- package/src/models/user.js +69 -69
- package/src/models/visitor.js +0 -0
- package/src/models/waterConcentrator.js +50 -50
- package/src/models/waterMeterSetting.js +25 -25
package/src/models/module.js
CHANGED
|
@@ -1,21 +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;
|
|
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;
|
|
@@ -1,23 +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;
|
|
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;
|
|
@@ -1,21 +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);
|
|
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
21
|
module.exports = SMSAfricastalking
|
|
@@ -1,17 +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);
|
|
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
17
|
module.exports = SMSMeliora
|
package/src/models/units.js
CHANGED
|
@@ -1,57 +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;
|
|
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;
|
package/src/models/user.js
CHANGED
|
@@ -1,69 +1,69 @@
|
|
|
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', 'Resident'],
|
|
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
|
-
customerData: [{
|
|
46
|
-
facilityId: {
|
|
47
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
48
|
-
ref: 'Facility',
|
|
49
|
-
},
|
|
50
|
-
customerId: {
|
|
51
|
-
type: mongoose.Schema.Types.ObjectId,
|
|
52
|
-
ref: 'Customer',
|
|
53
|
-
}
|
|
54
|
-
}],
|
|
55
|
-
password: {
|
|
56
|
-
type: String,
|
|
57
|
-
required: [true, 'Password is required'],
|
|
58
|
-
minlength: 8,
|
|
59
|
-
},
|
|
60
|
-
}, {
|
|
61
|
-
timestamps: true, // Automatically add createdAt and updatedAt fields
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
userSchema.index({ fullName: 'text', email: 'text' });
|
|
66
|
-
|
|
67
|
-
const User = mongoose.model('User', userSchema);
|
|
68
|
-
|
|
69
|
-
module.exports = User;
|
|
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', 'Resident'],
|
|
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
|
+
customerData: [{
|
|
46
|
+
facilityId: {
|
|
47
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
48
|
+
ref: 'Facility',
|
|
49
|
+
},
|
|
50
|
+
customerId: {
|
|
51
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
52
|
+
ref: 'Customer',
|
|
53
|
+
}
|
|
54
|
+
}],
|
|
55
|
+
password: {
|
|
56
|
+
type: String,
|
|
57
|
+
required: [true, 'Password is required'],
|
|
58
|
+
minlength: 8,
|
|
59
|
+
},
|
|
60
|
+
}, {
|
|
61
|
+
timestamps: true, // Automatically add createdAt and updatedAt fields
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
userSchema.index({ fullName: 'text', email: 'text' });
|
|
66
|
+
|
|
67
|
+
const User = mongoose.model('User', userSchema);
|
|
68
|
+
|
|
69
|
+
module.exports = User;
|
|
File without changes
|
|
@@ -1,50 +1,50 @@
|
|
|
1
|
-
const mongoose = require('mongoose');
|
|
2
|
-
|
|
3
|
-
const waterConcentratorSchema = new mongoose.Schema({
|
|
4
|
-
serialNumber: {
|
|
5
|
-
type: String,
|
|
6
|
-
required: true
|
|
7
|
-
},
|
|
8
|
-
manufacturer: {
|
|
9
|
-
type: String,
|
|
10
|
-
required: true
|
|
11
|
-
},
|
|
12
|
-
range: {
|
|
13
|
-
type: Number,
|
|
14
|
-
required: true
|
|
15
|
-
},
|
|
16
|
-
isInstalled: {
|
|
17
|
-
type: Boolean,
|
|
18
|
-
required: true
|
|
19
|
-
},
|
|
20
|
-
isFaulty: {
|
|
21
|
-
type: Boolean,
|
|
22
|
-
required: true
|
|
23
|
-
},
|
|
24
|
-
inStock: {
|
|
25
|
-
type: Boolean,
|
|
26
|
-
required: true
|
|
27
|
-
},
|
|
28
|
-
status: {
|
|
29
|
-
type: String,
|
|
30
|
-
required: true,
|
|
31
|
-
enum: ['Offline', 'Online']
|
|
32
|
-
},
|
|
33
|
-
location: {
|
|
34
|
-
lat: {
|
|
35
|
-
type: Number,
|
|
36
|
-
required: false
|
|
37
|
-
},
|
|
38
|
-
long: {
|
|
39
|
-
type: Number,
|
|
40
|
-
required: false
|
|
41
|
-
}
|
|
42
|
-
},
|
|
43
|
-
facilityId: {
|
|
44
|
-
type: [String], // Assuming facilityId is an array of strings
|
|
45
|
-
required: true
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
const WaterConcentrator = mongoose.model('WaterConcentrator', waterConcentratorSchema);
|
|
50
|
-
module.exports = WaterConcentrator;
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const waterConcentratorSchema = new mongoose.Schema({
|
|
4
|
+
serialNumber: {
|
|
5
|
+
type: String,
|
|
6
|
+
required: true
|
|
7
|
+
},
|
|
8
|
+
manufacturer: {
|
|
9
|
+
type: String,
|
|
10
|
+
required: true
|
|
11
|
+
},
|
|
12
|
+
range: {
|
|
13
|
+
type: Number,
|
|
14
|
+
required: true
|
|
15
|
+
},
|
|
16
|
+
isInstalled: {
|
|
17
|
+
type: Boolean,
|
|
18
|
+
required: true
|
|
19
|
+
},
|
|
20
|
+
isFaulty: {
|
|
21
|
+
type: Boolean,
|
|
22
|
+
required: true
|
|
23
|
+
},
|
|
24
|
+
inStock: {
|
|
25
|
+
type: Boolean,
|
|
26
|
+
required: true
|
|
27
|
+
},
|
|
28
|
+
status: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: true,
|
|
31
|
+
enum: ['Offline', 'Online']
|
|
32
|
+
},
|
|
33
|
+
location: {
|
|
34
|
+
lat: {
|
|
35
|
+
type: Number,
|
|
36
|
+
required: false
|
|
37
|
+
},
|
|
38
|
+
long: {
|
|
39
|
+
type: Number,
|
|
40
|
+
required: false
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
facilityId: {
|
|
44
|
+
type: [String], // Assuming facilityId is an array of strings
|
|
45
|
+
required: true
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const WaterConcentrator = mongoose.model('WaterConcentrator', waterConcentratorSchema);
|
|
50
|
+
module.exports = WaterConcentrator;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
const mongoose = require('mongoose');
|
|
2
|
-
|
|
3
|
-
const waterMeterSettingsSchema = mongoose.Schema({
|
|
4
|
-
manufacturers: {
|
|
5
|
-
type: [String],
|
|
6
|
-
required: false
|
|
7
|
-
},
|
|
8
|
-
meterSizes: {
|
|
9
|
-
type: [String],
|
|
10
|
-
required: false
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
// Middleware to ensure only one record exists
|
|
15
|
-
waterMeterSettingsSchema.pre('save', async function (next) {
|
|
16
|
-
const existingSettings = await WaterMeterSettings.findOne();
|
|
17
|
-
if (existingSettings && !existingSettings._id.equals(this._id)) {
|
|
18
|
-
throw new Error('Only one water meter settings record is allowed.');
|
|
19
|
-
}
|
|
20
|
-
next();
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
const WaterMeterSettings = mongoose.model("WaterMeterSettings", waterMeterSettingsSchema);
|
|
24
|
-
|
|
25
|
-
module.exports = WaterMeterSettings;
|
|
1
|
+
const mongoose = require('mongoose');
|
|
2
|
+
|
|
3
|
+
const waterMeterSettingsSchema = mongoose.Schema({
|
|
4
|
+
manufacturers: {
|
|
5
|
+
type: [String],
|
|
6
|
+
required: false
|
|
7
|
+
},
|
|
8
|
+
meterSizes: {
|
|
9
|
+
type: [String],
|
|
10
|
+
required: false
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
// Middleware to ensure only one record exists
|
|
15
|
+
waterMeterSettingsSchema.pre('save', async function (next) {
|
|
16
|
+
const existingSettings = await WaterMeterSettings.findOne();
|
|
17
|
+
if (existingSettings && !existingSettings._id.equals(this._id)) {
|
|
18
|
+
throw new Error('Only one water meter settings record is allowed.');
|
|
19
|
+
}
|
|
20
|
+
next();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const WaterMeterSettings = mongoose.model("WaterMeterSettings", waterMeterSettingsSchema);
|
|
24
|
+
|
|
25
|
+
module.exports = WaterMeterSettings;
|