scheduler-node-models 1.2.29 → 1.2.30

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.30",
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.
@@ -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.