payservedb 6.8.9 → 6.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "payservedb",
3
- "version": "6.8.9",
3
+ "version": "6.9.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -137,7 +137,8 @@ const facilityInvoiceContractSchema = new mongoose.Schema(
137
137
  },
138
138
  signedContractDocument: {
139
139
  type: String,
140
- required: true,
140
+ required: false, // Changed from required: true
141
+ default: null, // Added default value
141
142
  },
142
143
  status: {
143
144
  type: String,
@@ -146,7 +147,7 @@ const facilityInvoiceContractSchema = new mongoose.Schema(
146
147
  },
147
148
  active: {
148
149
  type: Boolean,
149
- default: true,
150
+ default: false, // Changed default to false since contracts start inactive
150
151
  },
151
152
  header: {
152
153
  companyName: {
@@ -246,6 +247,19 @@ const facilityInvoiceContractSchema = new mongoose.Schema(
246
247
  },
247
248
  );
248
249
 
250
+ // Add validation middleware to ensure signed contracts have documents
251
+ facilityInvoiceContractSchema.pre("save", function (next) {
252
+ if (this.status === "signed" && !this.signedContractDocument) {
253
+ return next(
254
+ new Error("Signed contracts must have a signed contract document"),
255
+ );
256
+ }
257
+ if (this.active === true && this.status !== "signed") {
258
+ return next(new Error("Only signed contracts can be active"));
259
+ }
260
+ next();
261
+ });
262
+
249
263
  const FacilityInvoiceContract = mongoose.model(
250
264
  "FacilityInvoiceContract",
251
265
  facilityInvoiceContractSchema,