payservedb 5.6.2 → 5.6.4
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 +2 -1
- package/package.json +1 -1
- package/src/models/billerAddress.js +117 -0
- package/src/models/expense_category.js +27 -1
- package/src/models/water_meter_settings.js +27 -1
package/index.js
CHANGED
|
@@ -172,7 +172,8 @@ const models = {
|
|
|
172
172
|
PendingCredential: require('./src/models/pendingCredentials'),
|
|
173
173
|
UnitManagementTemplate: require('./src/models/unitManagementTemplate'),
|
|
174
174
|
PropertyManagerRevenue: require('./src/models/propertyManagerRevenue'),
|
|
175
|
-
PropertyManagerContract: require('./src/models/propertyManagerContract')
|
|
175
|
+
PropertyManagerContract: require('./src/models/propertyManagerContract'),
|
|
176
|
+
BillerAddress: require('./src/models/billerAddress')
|
|
176
177
|
};
|
|
177
178
|
|
|
178
179
|
// Function to get models dynamically from a specific database connection
|
package/package.json
CHANGED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
const mongoose = require("mongoose");
|
|
2
|
+
|
|
3
|
+
// Define the schema for Biller Address
|
|
4
|
+
const billerAddressSchema = new mongoose.Schema(
|
|
5
|
+
{
|
|
6
|
+
name: {
|
|
7
|
+
type: String,
|
|
8
|
+
required: [true, "Address name is required"],
|
|
9
|
+
trim: true,
|
|
10
|
+
minlength: [1, "Address name must be at least 1 character long"],
|
|
11
|
+
},
|
|
12
|
+
companyName: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: [true, "Company name is required"],
|
|
15
|
+
trim: true,
|
|
16
|
+
},
|
|
17
|
+
website: {
|
|
18
|
+
type: String,
|
|
19
|
+
trim: true,
|
|
20
|
+
validate: {
|
|
21
|
+
validator: function (v) {
|
|
22
|
+
if (!v) return true; // Optional field
|
|
23
|
+
return /^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-])\/?$/.test(v);
|
|
24
|
+
},
|
|
25
|
+
message: "Please enter a valid website URL"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
email: {
|
|
29
|
+
type: String,
|
|
30
|
+
required: [true, "Email is required"],
|
|
31
|
+
trim: true,
|
|
32
|
+
lowercase: true,
|
|
33
|
+
validate: {
|
|
34
|
+
validator: function (v) {
|
|
35
|
+
return /^\w+([\.-]?\w+)@\w+([\.-]?\w+)(\.\w{2,3})+$/.test(v);
|
|
36
|
+
},
|
|
37
|
+
message: "Please enter a valid email address"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
phone: {
|
|
41
|
+
type: String,
|
|
42
|
+
trim: true,
|
|
43
|
+
},
|
|
44
|
+
address: {
|
|
45
|
+
type: String,
|
|
46
|
+
required: [true, "Address is required"],
|
|
47
|
+
trim: true,
|
|
48
|
+
},
|
|
49
|
+
city: {
|
|
50
|
+
type: String,
|
|
51
|
+
required: [true, "City is required"],
|
|
52
|
+
trim: true,
|
|
53
|
+
},
|
|
54
|
+
state: {
|
|
55
|
+
type: String,
|
|
56
|
+
trim: true,
|
|
57
|
+
},
|
|
58
|
+
country: {
|
|
59
|
+
type: String,
|
|
60
|
+
required: [true, "Country is required"],
|
|
61
|
+
trim: true,
|
|
62
|
+
default: "Kenya"
|
|
63
|
+
},
|
|
64
|
+
postalCode: {
|
|
65
|
+
type: String,
|
|
66
|
+
trim: true,
|
|
67
|
+
},
|
|
68
|
+
logo: {
|
|
69
|
+
type: String, // Will store the file path/URL of the uploaded logo
|
|
70
|
+
required: false,
|
|
71
|
+
},
|
|
72
|
+
isDefault: {
|
|
73
|
+
type: Boolean,
|
|
74
|
+
default: false,
|
|
75
|
+
},
|
|
76
|
+
facilityId: {
|
|
77
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
78
|
+
ref: "Facility",
|
|
79
|
+
required: true,
|
|
80
|
+
},
|
|
81
|
+
createdBy: {
|
|
82
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
83
|
+
ref: "User",
|
|
84
|
+
},
|
|
85
|
+
updatedBy: {
|
|
86
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
87
|
+
ref: "User",
|
|
88
|
+
}
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
timestamps: true,
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
|
|
95
|
+
// Index for efficient queries
|
|
96
|
+
billerAddressSchema.index({ facilityId: 1 });
|
|
97
|
+
billerAddressSchema.index({ facilityId: 1, isDefault: 1 });
|
|
98
|
+
|
|
99
|
+
// Pre-save middleware to ensure only one default address per facility
|
|
100
|
+
billerAddressSchema.pre('save', async function (next) {
|
|
101
|
+
if (this.isDefault && this.isModified('isDefault')) {
|
|
102
|
+
// If this address is being set as default, unset all other defaults for this facility
|
|
103
|
+
await this.constructor.updateMany(
|
|
104
|
+
{
|
|
105
|
+
facilityId: this.facilityId,
|
|
106
|
+
_id: { $ne: this._id }
|
|
107
|
+
},
|
|
108
|
+
{ $set: { isDefault: false } }
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
next();
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
// Compile the model from the schema
|
|
115
|
+
const BillerAddress = mongoose.model("BillerAddress", billerAddressSchema);
|
|
116
|
+
|
|
117
|
+
module.exports = BillerAddress;
|
|
@@ -10,7 +10,33 @@ const expenseCategorySchema = new mongoose.Schema({
|
|
|
10
10
|
type: String,
|
|
11
11
|
required: true,
|
|
12
12
|
trim: true
|
|
13
|
-
}
|
|
13
|
+
},
|
|
14
|
+
glAccounts: {
|
|
15
|
+
invoice: {
|
|
16
|
+
debit: {
|
|
17
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
18
|
+
ref: "GLAccount",
|
|
19
|
+
required: false,
|
|
20
|
+
},
|
|
21
|
+
credit: {
|
|
22
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
23
|
+
ref: "GLAccount",
|
|
24
|
+
required: false,
|
|
25
|
+
}
|
|
26
|
+
},
|
|
27
|
+
payment: {
|
|
28
|
+
debit: {
|
|
29
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
30
|
+
ref: "GLAccount",
|
|
31
|
+
required: false,
|
|
32
|
+
},
|
|
33
|
+
credit: {
|
|
34
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
35
|
+
ref: "GLAccount",
|
|
36
|
+
required: false,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
},
|
|
14
40
|
}, {
|
|
15
41
|
timestamps: true
|
|
16
42
|
});
|
|
@@ -79,7 +79,33 @@ const waterMeterSettingsSchema = new mongoose.Schema({
|
|
|
79
79
|
allNotifications: {
|
|
80
80
|
type: Boolean,
|
|
81
81
|
default: false
|
|
82
|
-
}
|
|
82
|
+
},
|
|
83
|
+
glAccounts: {
|
|
84
|
+
invoice: {
|
|
85
|
+
debit: {
|
|
86
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
87
|
+
ref: "GLAccount",
|
|
88
|
+
required: false,
|
|
89
|
+
},
|
|
90
|
+
credit: {
|
|
91
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
92
|
+
ref: "GLAccount",
|
|
93
|
+
required: false,
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
payment: {
|
|
97
|
+
debit: {
|
|
98
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
99
|
+
ref: "GLAccount",
|
|
100
|
+
required: false,
|
|
101
|
+
},
|
|
102
|
+
credit: {
|
|
103
|
+
type: mongoose.Schema.Types.ObjectId,
|
|
104
|
+
ref: "GLAccount",
|
|
105
|
+
required: false,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
},
|
|
83
109
|
}, {
|
|
84
110
|
timestamps: true
|
|
85
111
|
});
|