scheduler-node-models 1.2.28 → 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
|
@@ -167,6 +167,23 @@ 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;
|
|
182
|
+
/**
|
|
183
|
+
* The function will remove a particular assignment from the assignment list
|
|
184
|
+
* @param id The numeric identifier for the assignment to remove.
|
|
185
|
+
*/
|
|
186
|
+
removeAssignment(id: number): void;
|
|
170
187
|
/**
|
|
171
188
|
* This method is used to add a new variation to the employee. It will determine the
|
|
172
189
|
* new variation's identifier and add that along with site and start date to the new
|
|
@@ -176,10 +193,29 @@ export declare class Employee implements IEmployee {
|
|
|
176
193
|
*/
|
|
177
194
|
addVariation(site: string, start: Date): void;
|
|
178
195
|
/**
|
|
179
|
-
*
|
|
180
|
-
*
|
|
196
|
+
* This method will update the selected variation with an update a single
|
|
197
|
+
* field in the selected variation. If the variation isn't found, an error
|
|
198
|
+
* will be transmitted to the requestor.
|
|
199
|
+
* @param varID A numeric value for the variation to change.
|
|
200
|
+
* @param field A string value for the data member to change.
|
|
201
|
+
* @param value A string value representing the data member's new value.
|
|
202
|
+
* @param workday (Optional) a numeric value for the workday to update if the update
|
|
203
|
+
* field is in a variation workday.
|
|
181
204
|
*/
|
|
182
|
-
|
|
205
|
+
updateVariation(varID: number, field: string, value: string, workday?: number): void;
|
|
206
|
+
/**
|
|
207
|
+
* This method will be used to convert a date string in the format of 2006-01-02 to
|
|
208
|
+
* a Date object with that date.
|
|
209
|
+
* @param date A string value in the correct format
|
|
210
|
+
* @returns
|
|
211
|
+
*/
|
|
212
|
+
private getDateFromString;
|
|
213
|
+
/**
|
|
214
|
+
* This method will be used to remove a single variation from the employee's variation
|
|
215
|
+
* list. An error will be thrown if the variation is not found.
|
|
216
|
+
* @param varID A numeric value for the identifier of the variation to delete.
|
|
217
|
+
*/
|
|
218
|
+
removeVariation(varID: number): void;
|
|
183
219
|
/**
|
|
184
220
|
* This function will determine if a labor code (charge number and extension) is the
|
|
185
221
|
* employee's primary code for the date given.
|
|
@@ -566,28 +566,81 @@ class Employee {
|
|
|
566
566
|
this.assignments.push(newAsgmt);
|
|
567
567
|
}
|
|
568
568
|
/**
|
|
569
|
-
* This method
|
|
570
|
-
*
|
|
571
|
-
*
|
|
572
|
-
* @param
|
|
573
|
-
* @param
|
|
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.
|
|
574
578
|
*/
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
this.
|
|
579
|
-
if (
|
|
580
|
-
|
|
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;
|
|
581
639
|
}
|
|
582
640
|
});
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
newVari.site = site;
|
|
587
|
-
newVari.startdate = new Date(start);
|
|
588
|
-
newVari.enddate = new Date(start);
|
|
589
|
-
this.variations.push(newVari);
|
|
590
|
-
this.variations.sort((a, b) => a.compareTo(b));
|
|
641
|
+
if (!found) {
|
|
642
|
+
throw new Error('Assignment not found');
|
|
643
|
+
}
|
|
591
644
|
}
|
|
592
645
|
/**
|
|
593
646
|
* The function will remove a particular assignment from the assignment list
|
|
@@ -620,6 +673,124 @@ class Employee {
|
|
|
620
673
|
this.assignments.splice(pos, 1);
|
|
621
674
|
}
|
|
622
675
|
}
|
|
676
|
+
/**
|
|
677
|
+
* This method is used to add a new variation to the employee. It will determine the
|
|
678
|
+
* new variation's identifier and add that along with site and start date to the new
|
|
679
|
+
* variation. The variation's enddate will match the start date at this time.
|
|
680
|
+
* @param site A string value for the site identifier.
|
|
681
|
+
* @param start A data value for the start of this variation.
|
|
682
|
+
*/
|
|
683
|
+
addVariation(site, start) {
|
|
684
|
+
// start by getting and determing the next variation id number.
|
|
685
|
+
let newID = -1;
|
|
686
|
+
this.variations.forEach(vari => {
|
|
687
|
+
if (vari.id > newID) {
|
|
688
|
+
newID = vari.id;
|
|
689
|
+
}
|
|
690
|
+
});
|
|
691
|
+
newID++;
|
|
692
|
+
const newVari = new variation_1.Variation();
|
|
693
|
+
newVari.id = newID;
|
|
694
|
+
newVari.site = site;
|
|
695
|
+
newVari.startdate = new Date(start);
|
|
696
|
+
newVari.enddate = new Date(start);
|
|
697
|
+
this.variations.push(newVari);
|
|
698
|
+
this.variations.sort((a, b) => a.compareTo(b));
|
|
699
|
+
}
|
|
700
|
+
/**
|
|
701
|
+
* This method will update the selected variation with an update a single
|
|
702
|
+
* field in the selected variation. If the variation isn't found, an error
|
|
703
|
+
* will be transmitted to the requestor.
|
|
704
|
+
* @param varID A numeric value for the variation to change.
|
|
705
|
+
* @param field A string value for the data member to change.
|
|
706
|
+
* @param value A string value representing the data member's new value.
|
|
707
|
+
* @param workday (Optional) a numeric value for the workday to update if the update
|
|
708
|
+
* field is in a variation workday.
|
|
709
|
+
*/
|
|
710
|
+
updateVariation(varID, field, value, workday) {
|
|
711
|
+
this.variations.sort((a, b) => a.compareTo(b));
|
|
712
|
+
let found = false;
|
|
713
|
+
this.variations.forEach((vari, v) => {
|
|
714
|
+
if (vari.id === varID) {
|
|
715
|
+
found = true;
|
|
716
|
+
switch (field.toLowerCase()) {
|
|
717
|
+
case "site":
|
|
718
|
+
vari.site = value;
|
|
719
|
+
break;
|
|
720
|
+
case "mids":
|
|
721
|
+
case "ismids":
|
|
722
|
+
vari.mids = Boolean(value);
|
|
723
|
+
break;
|
|
724
|
+
case "dates":
|
|
725
|
+
vari.schedule.showdates = Boolean(value);
|
|
726
|
+
break;
|
|
727
|
+
case "start":
|
|
728
|
+
case "startdate":
|
|
729
|
+
vari.startdate = this.getDateFromString(value);
|
|
730
|
+
break;
|
|
731
|
+
case "end":
|
|
732
|
+
case "enddate":
|
|
733
|
+
vari.enddate = this.getDateFromString(value);
|
|
734
|
+
break;
|
|
735
|
+
case "changeschedule":
|
|
736
|
+
vari.schedule.setScheduleDays(Number(value));
|
|
737
|
+
break;
|
|
738
|
+
case "workday-code":
|
|
739
|
+
case "workday-workcenter":
|
|
740
|
+
case "workday-hours":
|
|
741
|
+
case "workday-copy":
|
|
742
|
+
const wparts = field.split('-');
|
|
743
|
+
if (workday) {
|
|
744
|
+
vari.updateWorkday(workday, wparts[1], value);
|
|
745
|
+
}
|
|
746
|
+
break;
|
|
747
|
+
}
|
|
748
|
+
this.variations[v] = vari;
|
|
749
|
+
}
|
|
750
|
+
});
|
|
751
|
+
if (!found) {
|
|
752
|
+
throw new Error('Variation not found');
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
/**
|
|
756
|
+
* This method will be used to convert a date string in the format of 2006-01-02 to
|
|
757
|
+
* a Date object with that date.
|
|
758
|
+
* @param date A string value in the correct format
|
|
759
|
+
* @returns
|
|
760
|
+
*/
|
|
761
|
+
getDateFromString(date) {
|
|
762
|
+
const reDateFormat = new RegExp('^[0-9]{4}\-[0-9]{2}\-[0-9]{2}$');
|
|
763
|
+
if (reDateFormat.test(date)) {
|
|
764
|
+
const parts = date.split('-');
|
|
765
|
+
const year = parseInt(parts[0]);
|
|
766
|
+
const month = parseInt(parts[1]);
|
|
767
|
+
const day = parseInt(parts[2]);
|
|
768
|
+
const result = new Date(Date.UTC(year, month - 1, day));
|
|
769
|
+
return result;
|
|
770
|
+
}
|
|
771
|
+
else {
|
|
772
|
+
throw new Error('Date not in correct format (yyyy-mm-dd)');
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
/**
|
|
776
|
+
* This method will be used to remove a single variation from the employee's variation
|
|
777
|
+
* list. An error will be thrown if the variation is not found.
|
|
778
|
+
* @param varID A numeric value for the identifier of the variation to delete.
|
|
779
|
+
*/
|
|
780
|
+
removeVariation(varID) {
|
|
781
|
+
let found = -1;
|
|
782
|
+
this.variations.forEach((vari, v) => {
|
|
783
|
+
if (vari.id === varID) {
|
|
784
|
+
found = v;
|
|
785
|
+
}
|
|
786
|
+
});
|
|
787
|
+
if (found >= 0) {
|
|
788
|
+
this.variations.splice(found, 1);
|
|
789
|
+
}
|
|
790
|
+
else {
|
|
791
|
+
throw new Error('Variation not found');
|
|
792
|
+
}
|
|
793
|
+
}
|
|
623
794
|
/**
|
|
624
795
|
* This function will determine if a labor code (charge number and extension) is the
|
|
625
796
|
* employee's primary code for the date given.
|