@oneuptime/common 7.0.4030 → 7.0.4034
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/Server/Services/OnCallDutyPolicyScheduleService.ts +92 -59
- package/Types/OnCallDutyPolicy/Layer.ts +65 -35
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js +41 -32
- package/build/dist/Server/Services/OnCallDutyPolicyScheduleService.js.map +1 -1
- package/build/dist/Types/OnCallDutyPolicy/Layer.js +57 -34
- package/build/dist/Types/OnCallDutyPolicy/Layer.js.map +1 -1
- package/package.json +2 -2
|
@@ -30,6 +30,8 @@ import Timezone from "../../Types/Timezone";
|
|
|
30
30
|
import logger from "../Utils/Logger";
|
|
31
31
|
|
|
32
32
|
export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
33
|
+
private layerUtil = new LayerUtil();
|
|
34
|
+
|
|
33
35
|
public constructor() {
|
|
34
36
|
super(OnCallDutyPolicySchedule);
|
|
35
37
|
}
|
|
@@ -377,32 +379,43 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
377
379
|
rosterStartAt: Date | null;
|
|
378
380
|
nextRosterStartAt: Date | null;
|
|
379
381
|
}> {
|
|
380
|
-
logger.debug(
|
|
382
|
+
logger.debug(
|
|
383
|
+
"refreshCurrentUserIdAndHandoffTimeInSchedule called with scheduleId: " +
|
|
384
|
+
scheduleId.toString(),
|
|
385
|
+
);
|
|
381
386
|
|
|
382
387
|
// get previoius result.
|
|
383
|
-
logger.debug(
|
|
388
|
+
logger.debug(
|
|
389
|
+
"Fetching previous schedule information for scheduleId: " +
|
|
390
|
+
scheduleId.toString(),
|
|
391
|
+
);
|
|
384
392
|
const onCallSchedule: OnCallDutyPolicySchedule | null =
|
|
385
393
|
await this.findOneById({
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
394
|
+
id: scheduleId,
|
|
395
|
+
select: {
|
|
396
|
+
currentUserIdOnRoster: true,
|
|
397
|
+
rosterHandoffAt: true,
|
|
398
|
+
nextUserIdOnRoster: true,
|
|
399
|
+
rosterNextHandoffAt: true,
|
|
400
|
+
rosterStartAt: true,
|
|
401
|
+
rosterNextStartAt: true,
|
|
402
|
+
},
|
|
403
|
+
props: {
|
|
404
|
+
isRoot: true,
|
|
405
|
+
},
|
|
398
406
|
});
|
|
399
407
|
|
|
400
408
|
if (!onCallSchedule) {
|
|
401
|
-
logger.debug(
|
|
409
|
+
logger.debug(
|
|
410
|
+
"Schedule not found for scheduleId: " + scheduleId.toString(),
|
|
411
|
+
);
|
|
402
412
|
throw new BadDataException("Schedule not found");
|
|
403
413
|
}
|
|
404
414
|
|
|
405
|
-
logger.debug(
|
|
415
|
+
logger.debug(
|
|
416
|
+
"Previous schedule information fetched for scheduleId: " +
|
|
417
|
+
scheduleId.toString(),
|
|
418
|
+
);
|
|
406
419
|
|
|
407
420
|
const previousInformation: {
|
|
408
421
|
currentUserIdOnRoster: ObjectID | null;
|
|
@@ -422,7 +435,10 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
422
435
|
|
|
423
436
|
logger.debug(previousInformation);
|
|
424
437
|
|
|
425
|
-
logger.debug(
|
|
438
|
+
logger.debug(
|
|
439
|
+
"Fetching new schedule information for scheduleId: " +
|
|
440
|
+
scheduleId.toString(),
|
|
441
|
+
);
|
|
426
442
|
|
|
427
443
|
const newInformation: {
|
|
428
444
|
currentUserId: ObjectID | null;
|
|
@@ -435,41 +451,50 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
435
451
|
|
|
436
452
|
logger.debug(newInformation);
|
|
437
453
|
|
|
438
|
-
logger.debug(
|
|
454
|
+
logger.debug(
|
|
455
|
+
"Updating schedule with new information for scheduleId: " +
|
|
456
|
+
scheduleId.toString(),
|
|
457
|
+
);
|
|
439
458
|
|
|
440
459
|
await this.updateOneById({
|
|
441
460
|
id: scheduleId!,
|
|
442
461
|
data: {
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
462
|
+
currentUserIdOnRoster: newInformation.currentUserId,
|
|
463
|
+
rosterHandoffAt: newInformation.handOffTimeAt,
|
|
464
|
+
nextUserIdOnRoster: newInformation.nextUserId,
|
|
465
|
+
rosterNextHandoffAt: newInformation.nextHandOffTimeAt,
|
|
466
|
+
rosterStartAt: newInformation.rosterStartAt,
|
|
467
|
+
rosterNextStartAt: newInformation.nextRosterStartAt,
|
|
449
468
|
},
|
|
450
469
|
props: {
|
|
451
|
-
|
|
452
|
-
|
|
470
|
+
isRoot: true,
|
|
471
|
+
ignoreHooks: true,
|
|
453
472
|
},
|
|
454
473
|
});
|
|
455
474
|
|
|
456
|
-
logger.debug(
|
|
475
|
+
logger.debug(
|
|
476
|
+
"Sending notifications for schedule handoff for scheduleId: " +
|
|
477
|
+
scheduleId.toString(),
|
|
478
|
+
);
|
|
457
479
|
|
|
458
480
|
// send notification to the users.
|
|
459
481
|
await this.sendNotificationToUserOnScheduleHandoff({
|
|
460
482
|
scheduleId: scheduleId,
|
|
461
483
|
previousInformation: previousInformation,
|
|
462
484
|
newInformation: {
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
485
|
+
currentUserIdOnRoster: newInformation.currentUserId,
|
|
486
|
+
rosterHandoffAt: newInformation.handOffTimeAt,
|
|
487
|
+
nextUserIdOnRoster: newInformation.nextUserId,
|
|
488
|
+
nextHandOffTimeAt: newInformation.nextHandOffTimeAt,
|
|
489
|
+
rosterStartAt: newInformation.rosterStartAt,
|
|
490
|
+
nextRosterStartAt: newInformation.nextRosterStartAt,
|
|
469
491
|
},
|
|
470
492
|
});
|
|
471
493
|
|
|
472
|
-
logger.debug(
|
|
494
|
+
logger.debug(
|
|
495
|
+
"Returning new schedule information for scheduleId: " +
|
|
496
|
+
scheduleId.toString(),
|
|
497
|
+
);
|
|
473
498
|
|
|
474
499
|
return newInformation;
|
|
475
500
|
}
|
|
@@ -484,8 +509,10 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
484
509
|
nextHandOffTimeAt: Date | null;
|
|
485
510
|
nextRosterStartAt: Date | null;
|
|
486
511
|
}> {
|
|
487
|
-
|
|
488
|
-
|
|
512
|
+
logger.debug(
|
|
513
|
+
"getCurrrentUserIdAndHandoffTimeInSchedule called with scheduleId: " +
|
|
514
|
+
scheduleId.toString(),
|
|
515
|
+
);
|
|
489
516
|
|
|
490
517
|
const resultReturn: {
|
|
491
518
|
rosterStartAt: Date | null;
|
|
@@ -503,48 +530,50 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
503
530
|
nextRosterStartAt: null,
|
|
504
531
|
};
|
|
505
532
|
|
|
506
|
-
logger.debug(
|
|
533
|
+
logger.debug("Fetching events for scheduleId: " + scheduleId.toString());
|
|
507
534
|
const events: Array<CalendarEvent> | null =
|
|
508
535
|
await this.getEventByIndexInSchedule({
|
|
509
536
|
scheduleId: scheduleId,
|
|
510
537
|
getNumberOfEvents: 2,
|
|
511
538
|
});
|
|
512
539
|
|
|
513
|
-
logger.debug(
|
|
540
|
+
logger.debug("Events fetched: " + JSON.stringify(events));
|
|
514
541
|
|
|
515
542
|
let currentEvent: CalendarEvent | null = events[0] || null;
|
|
516
543
|
let nextEvent: CalendarEvent | null = events[1] || null;
|
|
517
544
|
|
|
518
|
-
logger.debug(
|
|
519
|
-
logger.debug(
|
|
545
|
+
logger.debug("Current event: " + JSON.stringify(currentEvent));
|
|
546
|
+
logger.debug("Next event: " + JSON.stringify(nextEvent));
|
|
520
547
|
|
|
521
548
|
// if the current event start time in the future then the current event is the next event.
|
|
522
549
|
if (currentEvent && OneUptimeDate.isInTheFuture(currentEvent.start)) {
|
|
523
|
-
logger.debug(
|
|
550
|
+
logger.debug(
|
|
551
|
+
"Current event is in the future, treating it as next event.",
|
|
552
|
+
);
|
|
524
553
|
nextEvent = currentEvent;
|
|
525
554
|
currentEvent = null;
|
|
526
555
|
}
|
|
527
556
|
|
|
528
557
|
if (currentEvent) {
|
|
529
|
-
logger.debug(
|
|
558
|
+
logger.debug("Processing current event: " + JSON.stringify(currentEvent));
|
|
530
559
|
const userId: string | undefined = currentEvent?.title; // this is user id in string.
|
|
531
560
|
|
|
532
561
|
if (userId) {
|
|
533
|
-
logger.debug(
|
|
562
|
+
logger.debug("Current userId: " + userId);
|
|
534
563
|
resultReturn.currentUserId = new ObjectID(userId);
|
|
535
564
|
}
|
|
536
565
|
|
|
537
566
|
// get handOffTime
|
|
538
567
|
const handOffTime: Date | undefined = currentEvent?.end; // this is user id in string.
|
|
539
568
|
if (handOffTime) {
|
|
540
|
-
logger.debug(
|
|
569
|
+
logger.debug("Current handOffTime: " + handOffTime.toISOString());
|
|
541
570
|
resultReturn.handOffTimeAt = handOffTime;
|
|
542
571
|
}
|
|
543
572
|
|
|
544
573
|
// get start time
|
|
545
574
|
const startTime: Date | undefined = currentEvent?.start; // this is user id in string.
|
|
546
575
|
if (startTime) {
|
|
547
|
-
logger.debug(
|
|
576
|
+
logger.debug("Current rosterStartAt: " + startTime.toISOString());
|
|
548
577
|
resultReturn.rosterStartAt = startTime;
|
|
549
578
|
}
|
|
550
579
|
}
|
|
@@ -552,30 +581,30 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
552
581
|
// do the same for next event.
|
|
553
582
|
|
|
554
583
|
if (nextEvent) {
|
|
555
|
-
logger.debug(
|
|
584
|
+
logger.debug("Processing next event: " + JSON.stringify(nextEvent));
|
|
556
585
|
const userId: string | undefined = nextEvent?.title; // this is user id in string.
|
|
557
586
|
|
|
558
587
|
if (userId) {
|
|
559
|
-
logger.debug(
|
|
588
|
+
logger.debug("Next userId: " + userId);
|
|
560
589
|
resultReturn.nextUserId = new ObjectID(userId);
|
|
561
590
|
}
|
|
562
591
|
|
|
563
592
|
// get handOffTime
|
|
564
593
|
const handOffTime: Date | undefined = nextEvent?.end; // this is user id in string.
|
|
565
594
|
if (handOffTime) {
|
|
566
|
-
logger.debug(
|
|
595
|
+
logger.debug("Next handOffTime: " + handOffTime.toISOString());
|
|
567
596
|
resultReturn.nextHandOffTimeAt = handOffTime;
|
|
568
597
|
}
|
|
569
598
|
|
|
570
599
|
// get start time
|
|
571
600
|
const startTime: Date | undefined = nextEvent?.start; // this is user id in string.
|
|
572
601
|
if (startTime) {
|
|
573
|
-
logger.debug(
|
|
602
|
+
logger.debug("Next rosterStartAt: " + startTime.toISOString());
|
|
574
603
|
resultReturn.nextRosterStartAt = startTime;
|
|
575
604
|
}
|
|
576
605
|
}
|
|
577
606
|
|
|
578
|
-
logger.debug(
|
|
607
|
+
logger.debug("Returning result: " + JSON.stringify(resultReturn));
|
|
579
608
|
return resultReturn;
|
|
580
609
|
}
|
|
581
610
|
|
|
@@ -664,32 +693,36 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
664
693
|
scheduleId: ObjectID;
|
|
665
694
|
getNumberOfEvents: number; // which event would you like to get. First event, second event, etc.
|
|
666
695
|
}): Promise<Array<CalendarEvent>> {
|
|
667
|
-
logger.debug(
|
|
696
|
+
logger.debug(
|
|
697
|
+
"getEventByIndexInSchedule called with data: " + JSON.stringify(data),
|
|
698
|
+
);
|
|
668
699
|
|
|
669
700
|
const layerProps: Array<LayerProps> = await this.getScheduleLayerProps({
|
|
670
701
|
scheduleId: data.scheduleId,
|
|
671
702
|
});
|
|
672
703
|
|
|
673
|
-
logger.debug(
|
|
704
|
+
logger.debug("Layer properties fetched: " + JSON.stringify(layerProps));
|
|
674
705
|
|
|
675
706
|
if (layerProps.length === 0) {
|
|
676
|
-
logger.debug(
|
|
707
|
+
logger.debug(
|
|
708
|
+
"No layers found for scheduleId: " + data.scheduleId.toString(),
|
|
709
|
+
);
|
|
677
710
|
return [];
|
|
678
711
|
}
|
|
679
712
|
|
|
680
713
|
const currentStartTime: Date = OneUptimeDate.getCurrentDate();
|
|
681
|
-
logger.debug(
|
|
714
|
+
logger.debug("Current start time: " + currentStartTime.toISOString());
|
|
682
715
|
|
|
683
716
|
const currentEndTime: Date = OneUptimeDate.addRemoveYears(
|
|
684
717
|
currentStartTime,
|
|
685
718
|
1,
|
|
686
719
|
);
|
|
687
|
-
logger.debug(
|
|
720
|
+
logger.debug("Current end time: " + currentEndTime.toISOString());
|
|
688
721
|
|
|
689
722
|
const numberOfEventsToGet: number = data.getNumberOfEvents;
|
|
690
|
-
logger.debug(
|
|
723
|
+
logger.debug("Number of events to get: " + numberOfEventsToGet);
|
|
691
724
|
|
|
692
|
-
const events: Array<CalendarEvent> =
|
|
725
|
+
const events: Array<CalendarEvent> = this.layerUtil.getMultiLayerEvents(
|
|
693
726
|
{
|
|
694
727
|
layers: layerProps,
|
|
695
728
|
calendarStartDate: currentStartTime,
|
|
@@ -700,7 +733,7 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
700
733
|
},
|
|
701
734
|
);
|
|
702
735
|
|
|
703
|
-
logger.debug(
|
|
736
|
+
logger.debug("Events fetched: " + JSON.stringify(events));
|
|
704
737
|
|
|
705
738
|
return events;
|
|
706
739
|
}
|
|
@@ -723,7 +756,7 @@ export class Service extends DatabaseService<OnCallDutyPolicySchedule> {
|
|
|
723
756
|
1,
|
|
724
757
|
);
|
|
725
758
|
|
|
726
|
-
const events: Array<CalendarEvent> =
|
|
759
|
+
const events: Array<CalendarEvent> = this.layerUtil.getMultiLayerEvents(
|
|
727
760
|
{
|
|
728
761
|
layers: layerProps,
|
|
729
762
|
calendarStartDate: currentStartTime,
|
|
@@ -34,7 +34,7 @@ export interface PriorityCalendarEvents extends CalendarEvent {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
export default class LayerUtil {
|
|
37
|
-
public
|
|
37
|
+
public getEvents(
|
|
38
38
|
data: EventProps,
|
|
39
39
|
options?:
|
|
40
40
|
| {
|
|
@@ -44,11 +44,11 @@ export default class LayerUtil {
|
|
|
44
44
|
): Array<CalendarEvent> {
|
|
45
45
|
let events: Array<CalendarEvent> = [];
|
|
46
46
|
|
|
47
|
-
if (!
|
|
47
|
+
if (!this.isDataValid(data)) {
|
|
48
48
|
return [];
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
-
data =
|
|
51
|
+
data = this.sanitizeData(data);
|
|
52
52
|
|
|
53
53
|
let start: Date = data.calendarStartDate;
|
|
54
54
|
const end: Date = data.calendarEndDate;
|
|
@@ -78,7 +78,7 @@ export default class LayerUtil {
|
|
|
78
78
|
|
|
79
79
|
// before we do this, we need to update the user index.
|
|
80
80
|
|
|
81
|
-
currentUserIndex =
|
|
81
|
+
currentUserIndex = this.getCurrentUserIndexBasedOnHandoffTime({
|
|
82
82
|
rotation,
|
|
83
83
|
handOffTime,
|
|
84
84
|
currentUserIndex,
|
|
@@ -89,7 +89,7 @@ export default class LayerUtil {
|
|
|
89
89
|
|
|
90
90
|
// update handoff time to the same day as current start time
|
|
91
91
|
|
|
92
|
-
handOffTime =
|
|
92
|
+
handOffTime = this.moveHandsOffTimeAfterCurrentEventStartTime({
|
|
93
93
|
handOffTime,
|
|
94
94
|
currentEventStartTime,
|
|
95
95
|
rotation: data.rotation,
|
|
@@ -101,7 +101,7 @@ export default class LayerUtil {
|
|
|
101
101
|
|
|
102
102
|
if (OneUptimeDate.isBefore(end, handOffTime)) {
|
|
103
103
|
const trimmedStartAndEndTimes: Array<StartAndEndTime> =
|
|
104
|
-
|
|
104
|
+
this.trimStartAndEndTimesBasedOnRestrictionTimes({
|
|
105
105
|
eventStartTime: currentEventStartTime,
|
|
106
106
|
eventEndTime: end,
|
|
107
107
|
restrictionTimes: data.restrictionTimes,
|
|
@@ -109,7 +109,7 @@ export default class LayerUtil {
|
|
|
109
109
|
|
|
110
110
|
events = [
|
|
111
111
|
...events,
|
|
112
|
-
...
|
|
112
|
+
...this.getCalendarEventsFromStartAndEndDates(
|
|
113
113
|
trimmedStartAndEndTimes,
|
|
114
114
|
data.users,
|
|
115
115
|
currentUserIndex,
|
|
@@ -137,7 +137,7 @@ export default class LayerUtil {
|
|
|
137
137
|
currentEventEndTime,
|
|
138
138
|
1,
|
|
139
139
|
);
|
|
140
|
-
handOffTime =
|
|
140
|
+
handOffTime = this.moveHandsOffTimeAfterCurrentEventStartTime({
|
|
141
141
|
handOffTime,
|
|
142
142
|
currentEventStartTime,
|
|
143
143
|
rotation: data.rotation,
|
|
@@ -155,7 +155,7 @@ export default class LayerUtil {
|
|
|
155
155
|
// check restriction times. if the end time of the event is after the end time of the restriction times, we need to update the end time of the event.
|
|
156
156
|
|
|
157
157
|
const trimmedStartAndEndTimes: Array<StartAndEndTime> =
|
|
158
|
-
|
|
158
|
+
this.trimStartAndEndTimesBasedOnRestrictionTimes({
|
|
159
159
|
eventStartTime: currentEventStartTime,
|
|
160
160
|
eventEndTime: currentEventEndTime,
|
|
161
161
|
restrictionTimes: data.restrictionTimes,
|
|
@@ -163,7 +163,7 @@ export default class LayerUtil {
|
|
|
163
163
|
|
|
164
164
|
events = [
|
|
165
165
|
...events,
|
|
166
|
-
...
|
|
166
|
+
...this.getCalendarEventsFromStartAndEndDates(
|
|
167
167
|
trimmedStartAndEndTimes,
|
|
168
168
|
data.users,
|
|
169
169
|
currentUserIndex,
|
|
@@ -185,14 +185,14 @@ export default class LayerUtil {
|
|
|
185
185
|
|
|
186
186
|
// update the handoff time
|
|
187
187
|
|
|
188
|
-
handOffTime =
|
|
188
|
+
handOffTime = this.moveHandsOffTimeAfterCurrentEventStartTime({
|
|
189
189
|
handOffTime,
|
|
190
190
|
currentEventStartTime,
|
|
191
191
|
rotation: data.rotation,
|
|
192
192
|
});
|
|
193
193
|
|
|
194
194
|
// update the current user index
|
|
195
|
-
currentUserIndex =
|
|
195
|
+
currentUserIndex = this.incrementUserIndex(
|
|
196
196
|
currentUserIndex,
|
|
197
197
|
data.users.length,
|
|
198
198
|
);
|
|
@@ -216,7 +216,7 @@ export default class LayerUtil {
|
|
|
216
216
|
return events;
|
|
217
217
|
}
|
|
218
218
|
|
|
219
|
-
private
|
|
219
|
+
private sanitizeData(data: EventProps): EventProps {
|
|
220
220
|
if (!(data.restrictionTimes instanceof RestrictionTimes)) {
|
|
221
221
|
data.restrictionTimes = RestrictionTimes.fromJSON(data.restrictionTimes);
|
|
222
222
|
}
|
|
@@ -246,7 +246,7 @@ export default class LayerUtil {
|
|
|
246
246
|
return data;
|
|
247
247
|
}
|
|
248
248
|
|
|
249
|
-
private
|
|
249
|
+
private isDataValid(data: EventProps): boolean {
|
|
250
250
|
// if calendar end time is before the start time then return an empty array.
|
|
251
251
|
if (OneUptimeDate.isBefore(data.calendarEndDate, data.calendarStartDate)) {
|
|
252
252
|
return false;
|
|
@@ -267,7 +267,7 @@ export default class LayerUtil {
|
|
|
267
267
|
return true;
|
|
268
268
|
}
|
|
269
269
|
|
|
270
|
-
private
|
|
270
|
+
private moveHandsOffTimeAfterCurrentEventStartTime(data: {
|
|
271
271
|
handOffTime: Date;
|
|
272
272
|
currentEventStartTime: Date;
|
|
273
273
|
rotation: Recurring;
|
|
@@ -436,7 +436,7 @@ export default class LayerUtil {
|
|
|
436
436
|
return handOffTime;
|
|
437
437
|
}
|
|
438
438
|
|
|
439
|
-
private
|
|
439
|
+
private getCurrentUserIndexBasedOnHandoffTime(data: {
|
|
440
440
|
rotation: Recurring;
|
|
441
441
|
handOffTime: Date;
|
|
442
442
|
currentUserIndex: number;
|
|
@@ -523,7 +523,7 @@ export default class LayerUtil {
|
|
|
523
523
|
numberOfIntervalsBetweenStartAndHandoffTime * -1;
|
|
524
524
|
}
|
|
525
525
|
|
|
526
|
-
currentUserIndex =
|
|
526
|
+
currentUserIndex = this.incrementUserIndex(
|
|
527
527
|
currentUserIndex,
|
|
528
528
|
data.users.length,
|
|
529
529
|
numberOfIntervalsBetweenStartAndHandoffTime,
|
|
@@ -532,7 +532,7 @@ export default class LayerUtil {
|
|
|
532
532
|
return currentUserIndex;
|
|
533
533
|
}
|
|
534
534
|
|
|
535
|
-
public
|
|
535
|
+
public trimStartAndEndTimesBasedOnRestrictionTimes(data: {
|
|
536
536
|
eventStartTime: Date;
|
|
537
537
|
eventEndTime: Date;
|
|
538
538
|
restrictionTimes: RestrictionTimes;
|
|
@@ -565,7 +565,7 @@ export default class LayerUtil {
|
|
|
565
565
|
data.eventStartTime,
|
|
566
566
|
);
|
|
567
567
|
|
|
568
|
-
return
|
|
568
|
+
return this.getEventsByDailyRestriction({
|
|
569
569
|
eventStartTime: data.eventStartTime,
|
|
570
570
|
eventEndTime: data.eventEndTime,
|
|
571
571
|
restrictionStartAndEndTime: restrictionTimes.dayRestrictionTimes,
|
|
@@ -576,13 +576,13 @@ export default class LayerUtil {
|
|
|
576
576
|
}
|
|
577
577
|
|
|
578
578
|
if (restrictionTimes.restictionType === RestrictionType.Weekly) {
|
|
579
|
-
return
|
|
579
|
+
return this.getEventsByWeeklyRestriction(data);
|
|
580
580
|
}
|
|
581
581
|
|
|
582
582
|
return [];
|
|
583
583
|
}
|
|
584
584
|
|
|
585
|
-
public
|
|
585
|
+
public getEventsByWeeklyRestriction(data: {
|
|
586
586
|
eventStartTime: Date;
|
|
587
587
|
eventEndTime: Date;
|
|
588
588
|
restrictionTimes: RestrictionTimes;
|
|
@@ -604,11 +604,11 @@ export default class LayerUtil {
|
|
|
604
604
|
}
|
|
605
605
|
|
|
606
606
|
const restrictionStartAndEndTimes: Array<StartAndEndTime> =
|
|
607
|
-
|
|
607
|
+
this.getWeeklyRestrictionTimesForWeek(data);
|
|
608
608
|
|
|
609
609
|
for (const restrictionStartAndEndTime of restrictionStartAndEndTimes) {
|
|
610
610
|
const trimmedStartAndEndTimesForRestriction: Array<StartAndEndTime> =
|
|
611
|
-
|
|
611
|
+
this.getEventsByDailyRestriction({
|
|
612
612
|
eventStartTime: data.eventStartTime,
|
|
613
613
|
eventEndTime: data.eventEndTime,
|
|
614
614
|
restrictionStartAndEndTime: restrictionStartAndEndTime,
|
|
@@ -626,7 +626,7 @@ export default class LayerUtil {
|
|
|
626
626
|
return trimmedStartAndEndTimes;
|
|
627
627
|
}
|
|
628
628
|
|
|
629
|
-
public
|
|
629
|
+
public getWeeklyRestrictionTimesForWeek(data: {
|
|
630
630
|
eventStartTime: Date;
|
|
631
631
|
eventEndTime: Date;
|
|
632
632
|
restrictionTimes: RestrictionTimes;
|
|
@@ -691,7 +691,7 @@ export default class LayerUtil {
|
|
|
691
691
|
return startAndEndTimesOfWeeklyRestrictions;
|
|
692
692
|
}
|
|
693
693
|
|
|
694
|
-
public
|
|
694
|
+
public getEventsByDailyRestriction(data: {
|
|
695
695
|
eventStartTime: Date;
|
|
696
696
|
eventEndTime: Date;
|
|
697
697
|
restrictionStartAndEndTime: StartAndEndTime;
|
|
@@ -727,7 +727,7 @@ export default class LayerUtil {
|
|
|
727
727
|
|
|
728
728
|
// create a break clause. This loop executes 100 times at max.
|
|
729
729
|
|
|
730
|
-
const maxLoopCount: number =
|
|
730
|
+
const maxLoopCount: number = 50;
|
|
731
731
|
let loopCount: number = 0;
|
|
732
732
|
|
|
733
733
|
while (!reachedTheEndOfTheCurrentEvent) {
|
|
@@ -836,7 +836,7 @@ export default class LayerUtil {
|
|
|
836
836
|
|
|
837
837
|
// helper functions.
|
|
838
838
|
|
|
839
|
-
private
|
|
839
|
+
private incrementUserIndex(
|
|
840
840
|
currentIndex: number,
|
|
841
841
|
userArrayLength: number,
|
|
842
842
|
incrementBy?: number,
|
|
@@ -858,7 +858,7 @@ export default class LayerUtil {
|
|
|
858
858
|
return currentIndex;
|
|
859
859
|
}
|
|
860
860
|
|
|
861
|
-
private
|
|
861
|
+
private getCalendarEventsFromStartAndEndDates(
|
|
862
862
|
trimmedStartAndEndTimes: Array<StartAndEndTime>,
|
|
863
863
|
users: Array<UserModel>,
|
|
864
864
|
currentUserIndex: number,
|
|
@@ -882,7 +882,7 @@ export default class LayerUtil {
|
|
|
882
882
|
return events;
|
|
883
883
|
}
|
|
884
884
|
|
|
885
|
-
public
|
|
885
|
+
public getMultiLayerEvents(
|
|
886
886
|
data: MultiLayerProps,
|
|
887
887
|
options?:
|
|
888
888
|
| {
|
|
@@ -894,7 +894,7 @@ export default class LayerUtil {
|
|
|
894
894
|
let layerPriority: number = 1;
|
|
895
895
|
|
|
896
896
|
for (const layer of data.layers) {
|
|
897
|
-
const layerEvents: Array<CalendarEvent> =
|
|
897
|
+
const layerEvents: Array<CalendarEvent> = this.getEvents(
|
|
898
898
|
{
|
|
899
899
|
users: layer.users,
|
|
900
900
|
startDateTimeOfLayer: layer.startDateTimeOfLayer,
|
|
@@ -925,7 +925,7 @@ export default class LayerUtil {
|
|
|
925
925
|
// now remove the overlapping events
|
|
926
926
|
|
|
927
927
|
const nonOverlappingEvents: Array<CalendarEvent> =
|
|
928
|
-
|
|
928
|
+
this.removeOverlappingEvents(events);
|
|
929
929
|
|
|
930
930
|
if (options?.getNumberOfEvents !== undefined) {
|
|
931
931
|
if (nonOverlappingEvents.length > options.getNumberOfEvents) {
|
|
@@ -936,7 +936,7 @@ export default class LayerUtil {
|
|
|
936
936
|
return nonOverlappingEvents;
|
|
937
937
|
}
|
|
938
938
|
|
|
939
|
-
public
|
|
939
|
+
public removeOverlappingEvents(
|
|
940
940
|
events: PriorityCalendarEvents[],
|
|
941
941
|
): CalendarEvent[] {
|
|
942
942
|
// now remove overlapping events by priority and trim them by priority. Lower priority number will be kept and higher priority number will be trimmed.
|
|
@@ -947,6 +947,17 @@ export default class LayerUtil {
|
|
|
947
947
|
|
|
948
948
|
// now remove the overlapping events
|
|
949
949
|
|
|
950
|
+
// remove events where start time and end time are the same
|
|
951
|
+
|
|
952
|
+
events = events.filter((event: PriorityCalendarEvents) => {
|
|
953
|
+
return !OneUptimeDate.isSame(event.start, event.end);
|
|
954
|
+
});
|
|
955
|
+
|
|
956
|
+
// remove events where start time is after end time
|
|
957
|
+
events = events.filter((event: PriorityCalendarEvents) => {
|
|
958
|
+
return !OneUptimeDate.isBefore(event.end, event.start);
|
|
959
|
+
});
|
|
960
|
+
|
|
950
961
|
const finalEvents: PriorityCalendarEvents[] = [];
|
|
951
962
|
|
|
952
963
|
// sort events by start time
|
|
@@ -966,6 +977,16 @@ export default class LayerUtil {
|
|
|
966
977
|
for (const event of events) {
|
|
967
978
|
// trim the trimmed events by the current event based on priority
|
|
968
979
|
|
|
980
|
+
// if this event starts and end at the same time, we need to remove it
|
|
981
|
+
if (OneUptimeDate.isSame(event.start, event.end)) {
|
|
982
|
+
continue;
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
// if the end time of the event is before the start time, we need to remove it
|
|
986
|
+
if (OneUptimeDate.isBefore(event.end, event.start)) {
|
|
987
|
+
continue;
|
|
988
|
+
}
|
|
989
|
+
|
|
969
990
|
for (const finalEvent of finalEvents) {
|
|
970
991
|
// check if this final event overlaps with the current event
|
|
971
992
|
|
|
@@ -1027,17 +1048,26 @@ export default class LayerUtil {
|
|
|
1027
1048
|
|
|
1028
1049
|
// if an event starts and end at the same time, we need to remove it
|
|
1029
1050
|
|
|
1030
|
-
|
|
1051
|
+
for (let index: number = 0; index < finalEvents.length; index++) {
|
|
1052
|
+
const finalEvent: PriorityCalendarEvents | undefined =
|
|
1053
|
+
finalEvents[index];
|
|
1054
|
+
|
|
1055
|
+
if (!finalEvent) {
|
|
1056
|
+
continue;
|
|
1057
|
+
}
|
|
1058
|
+
|
|
1031
1059
|
if (OneUptimeDate.isSame(finalEvent.start, finalEvent.end)) {
|
|
1032
1060
|
finalEvents.splice(index, 1);
|
|
1061
|
+
index--; // Adjust index after removal
|
|
1062
|
+
continue;
|
|
1033
1063
|
}
|
|
1034
1064
|
|
|
1035
1065
|
// if any event ends before it starts, we need to remove it
|
|
1036
|
-
|
|
1037
1066
|
if (OneUptimeDate.isBefore(finalEvent.end, finalEvent.start)) {
|
|
1038
1067
|
finalEvents.splice(index, 1);
|
|
1068
|
+
index--; // Adjust index after removal
|
|
1039
1069
|
}
|
|
1040
|
-
}
|
|
1070
|
+
}
|
|
1041
1071
|
}
|
|
1042
1072
|
|
|
1043
1073
|
// convert PriorityCalendarEvents to CalendarEvents
|