scheduler-node-models 1.2.29 → 1.2.31

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": "scheduler-node-models",
3
- "version": "1.2.29",
3
+ "version": "1.2.31",
4
4
  "main": "index.js",
5
5
  "types": "index.d.ts",
6
6
  "files": [
@@ -167,6 +167,18 @@ export declare class Employee implements IEmployee {
167
167
  * @param start The date object used to mark the start of the assignment
168
168
  */
169
169
  addAssignment(site: string, wkctr: string, start: Date): void;
170
+ /**
171
+ * This method will be used to update an assignment already in the employee's
172
+ * list. It can throw errors for assignment not found and for missing data
173
+ * expected for the field to be update.
174
+ * @param id A numeric value for the assignment to update
175
+ * @param field A string value for the field to update
176
+ * @param value A string value for the update to the required field
177
+ * @param schedule (Optional) A numeric value for the assignment schedule to be updated
178
+ * @param workday (Optional) A numeric value for the assignment schedule workday to
179
+ * be updated.
180
+ */
181
+ updateAssignment(id: number, field: string, value: string, schedule?: number, workday?: number): void;
170
182
  /**
171
183
  * The function will remove a particular assignment from the assignment list
172
184
  * @param id The numeric identifier for the assignment to remove.
@@ -290,11 +302,10 @@ export declare class Employee implements IEmployee {
290
302
  * This function is used to update a leave balance object with a new annual year and
291
303
  * carry over amount.
292
304
  * @param year The numeric value for the year used as a key value
293
- * @param annual The numeric value for the employee's annual leave amount in hours.
294
- * @param carry The numeric value for the number of hours the employee brings forward
295
- * to this year.
305
+ * @param field The string value for the field to update
306
+ * @param carry The numeric value for the number of hours for that field.
296
307
  */
297
- updateLeaveBalance(year: number, annual: number, carry: number): void;
308
+ updateLeaveBalance(year: number, field: string, value: number): void;
298
309
  /**
299
310
  * This function will remove a leave balance from the employee's leave balance list.
300
311
  * @param year The numeric value for the year of the leave balance (primary key).
@@ -565,6 +565,83 @@ class Employee {
565
565
  }
566
566
  this.assignments.push(newAsgmt);
567
567
  }
568
+ /**
569
+ * This method will be used to update an assignment already in the employee's
570
+ * list. It can throw errors for assignment not found and for missing data
571
+ * expected for the field to be update.
572
+ * @param id A numeric value for the assignment to update
573
+ * @param field A string value for the field to update
574
+ * @param value A string value for the update to the required field
575
+ * @param schedule (Optional) A numeric value for the assignment schedule to be updated
576
+ * @param workday (Optional) A numeric value for the assignment schedule workday to
577
+ * be updated.
578
+ */
579
+ updateAssignment(id, field, value, schedule, workday) {
580
+ let found = false;
581
+ this.assignments.sort((a, b) => a.compareTo(b));
582
+ this.assignments.forEach((asgmt, i) => {
583
+ if (asgmt.id === id) {
584
+ found = true;
585
+ switch (field.toLowerCase()) {
586
+ case "site":
587
+ asgmt.site = value;
588
+ break;
589
+ case "workcenter":
590
+ asgmt.workcenter = value;
591
+ break;
592
+ case "start":
593
+ case "startdate":
594
+ asgmt.startDate = this.getDateFromString(value);
595
+ break;
596
+ case "end":
597
+ case "enddate":
598
+ asgmt.endDate = this.getDateFromString(value);
599
+ break;
600
+ case "rotationdate":
601
+ asgmt.rotationdate = this.getDateFromString(value);
602
+ break;
603
+ case "rotationdays":
604
+ asgmt.rotationdays = Number(value);
605
+ break;
606
+ case "addschedule":
607
+ asgmt.addSchedule(Number(value));
608
+ break;
609
+ case "removeschedule":
610
+ if (schedule) {
611
+ asgmt.removeSchedule(schedule);
612
+ }
613
+ else {
614
+ throw new Error('Assignment schedule id not provided');
615
+ }
616
+ break;
617
+ case "scheduledays":
618
+ if (schedule) {
619
+ asgmt.changeScheduleDays(schedule, Number(value));
620
+ }
621
+ else {
622
+ throw new Error('Assignment schedule id not provided');
623
+ }
624
+ break;
625
+ case "workday-code":
626
+ case "workday-workcenter":
627
+ case "workday-hours":
628
+ case "workday-copy":
629
+ const wparts = field.split('-');
630
+ if (schedule && workday) {
631
+ asgmt.updateWorkday(schedule, workday, wparts[1], value);
632
+ }
633
+ else {
634
+ throw new Error('Assignment schedule and/or workday id not provided');
635
+ }
636
+ break;
637
+ }
638
+ this.assignments[i] = asgmt;
639
+ }
640
+ });
641
+ if (!found) {
642
+ throw new Error('Assignment not found');
643
+ }
644
+ }
568
645
  /**
569
646
  * The function will remove a particular assignment from the assignment list
570
647
  * @param id The numeric identifier for the assignment to remove.
@@ -1026,30 +1103,35 @@ class Employee {
1026
1103
  this.balances.push(bal);
1027
1104
  this.balances.sort((a, b) => a.compareTo(b));
1028
1105
  }
1106
+ else {
1107
+ throw new Error('Leave Balance year already exists');
1108
+ }
1029
1109
  }
1030
1110
  /**
1031
1111
  * This function is used to update a leave balance object with a new annual year and
1032
1112
  * carry over amount.
1033
1113
  * @param year The numeric value for the year used as a key value
1034
- * @param annual The numeric value for the employee's annual leave amount in hours.
1035
- * @param carry The numeric value for the number of hours the employee brings forward
1036
- * to this year.
1114
+ * @param field The string value for the field to update
1115
+ * @param carry The numeric value for the number of hours for that field.
1037
1116
  */
1038
- updateLeaveBalance(year, annual, carry) {
1117
+ updateLeaveBalance(year, field, value) {
1039
1118
  let found = false;
1040
1119
  for (let lb = 0; lb < this.balances.length && !found; lb++) {
1041
1120
  if (this.balances[lb].year === year) {
1042
- this.balances[lb].annual = annual;
1043
- this.balances[lb].carryover = carry;
1121
+ found = true;
1122
+ switch (field.toLowerCase()) {
1123
+ case "annual":
1124
+ this.balances[lb].annual = value;
1125
+ break;
1126
+ case 'carry':
1127
+ case 'carryover':
1128
+ this.balances[lb].carryover = value;
1129
+ break;
1130
+ }
1044
1131
  }
1045
1132
  }
1046
1133
  if (!found) {
1047
- const lb = new balance_1.AnnualLeave({
1048
- year: year,
1049
- annual: annual,
1050
- carryover: carry
1051
- });
1052
- this.balances.push(lb);
1134
+ throw new Error('Leave Balance year not found');
1053
1135
  }
1054
1136
  this.balances.sort((a, b) => a.compareTo(b));
1055
1137
  }
@@ -1067,6 +1149,9 @@ class Employee {
1067
1149
  if (found >= 0) {
1068
1150
  this.balances.splice(found, 1);
1069
1151
  }
1152
+ else {
1153
+ throw new Error('Leave Balance year not found');
1154
+ }
1070
1155
  }
1071
1156
  /**
1072
1157
  * This is the employee leave section.