payservedb 6.3.9 → 6.4.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.3.9",
3
+ "version": "6.4.0",
4
4
  "main": "index.js",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1"
@@ -36,7 +36,15 @@ const dutyRosterSchema = new mongoose.Schema(
36
36
  ref: "MasterWorkplanAssignment",
37
37
  required: true,
38
38
  },
39
-
39
+ // Roster validity period
40
+ startDate: {
41
+ type: Date,
42
+ required: true,
43
+ },
44
+ endDate: {
45
+ type: Date,
46
+ required: true,
47
+ },
40
48
  // Regular weekly schedule - now array of time slots for each day
41
49
  weeklySchedule: {
42
50
  monday: [timeSlotSchema],
@@ -47,7 +55,6 @@ const dutyRosterSchema = new mongoose.Schema(
47
55
  saturday: [timeSlotSchema],
48
56
  sunday: [timeSlotSchema],
49
57
  },
50
-
51
58
  // For exceptions to the regular schedule
52
59
  exceptions: [
53
60
  {
@@ -65,7 +72,6 @@ const dutyRosterSchema = new mongoose.Schema(
65
72
  reason: String,
66
73
  },
67
74
  ],
68
-
69
75
  // Metadata
70
76
  metadata: {
71
77
  period: {
@@ -79,21 +85,14 @@ const dutyRosterSchema = new mongoose.Schema(
79
85
  },
80
86
  );
81
87
 
82
- // Status code definitions
83
- dutyRosterSchema.statics.STATUS_CODES = {
84
- ON: "On Duty",
85
- OFF: "Off Duty",
86
- AL: "Annual Leave",
87
- CL: "Casual Leave",
88
- "ML/PL": "Medical/Paternity Leave",
89
- PH: "Public Holiday",
90
- UI: "Unplanned Issues",
91
- };
92
-
93
- // Pre-save middleware to handle backward compatibility with old format
88
+ // Add validation to ensure endDate is after startDate
94
89
  dutyRosterSchema.pre("save", function (next) {
95
- const schedule = this.weeklySchedule;
90
+ // Validate date range
91
+ if (this.startDate && this.endDate && this.startDate >= this.endDate) {
92
+ return next(new Error("End date must be after start date"));
93
+ }
96
94
 
95
+ const schedule = this.weeklySchedule;
97
96
  // Convert any day that's not an array to an array with a single element
98
97
  for (const day of [
99
98
  "monday",
@@ -107,7 +106,6 @@ dutyRosterSchema.pre("save", function (next) {
107
106
  if (schedule[day] && !Array.isArray(schedule[day])) {
108
107
  schedule[day] = [schedule[day]];
109
108
  }
110
-
111
109
  // Ensure each day has at least one time slot
112
110
  if (!schedule[day] || schedule[day].length === 0) {
113
111
  schedule[day] = [
@@ -119,8 +117,22 @@ dutyRosterSchema.pre("save", function (next) {
119
117
  ];
120
118
  }
121
119
  }
122
-
123
120
  next();
124
121
  });
125
122
 
123
+ // Status code definitions
124
+ dutyRosterSchema.statics.STATUS_CODES = {
125
+ ON: "On Duty",
126
+ OFF: "Off Duty",
127
+ AL: "Annual Leave",
128
+ CL: "Casual Leave",
129
+ "ML/PL": "Medical/Paternity Leave",
130
+ PH: "Public Holiday",
131
+ UI: "Unplanned Issues",
132
+ };
133
+
134
+ // Add index for efficient date range queries
135
+ dutyRosterSchema.index({ startDate: 1, endDate: 1 });
136
+ dutyRosterSchema.index({ facilityId: 1, startDate: 1, endDate: 1 });
137
+
126
138
  module.exports = mongoose.model("DutyRoster", dutyRosterSchema);