From b38cc4c71cdfcdff3f265e4e09bc0576085861a4 Mon Sep 17 00:00:00 2001 From: miiila Date: Tue, 3 Oct 2017 16:14:14 +0200 Subject: [PATCH] fix: prevent duplication of schedules --- src/pagerduty.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/pagerduty.js b/src/pagerduty.js index 11b27df..5a99772 100644 --- a/src/pagerduty.js +++ b/src/pagerduty.js @@ -108,7 +108,7 @@ function processSchedules(allSchedules, days = [], cb) { const myEnd = moment.utc(entry.end); const myUserId = entry.user.id; const myUserName = entry.user.summary; - if (duplicities.myUserName == null) { duplicities.myUserName = []; } + if (duplicities[myUserName] == null) { duplicities[myUserName] = []; } otherSchedules.forEach((crossSchedule) => { crossSchedule.entries.forEach((crossCheckEntry) => { let overlap = false; @@ -118,13 +118,15 @@ function processSchedules(allSchedules, days = [], cb) { const crossCheckStart = moment.utc(crossCheckEntry.start); const crossCheckEnd = moment.utc(crossCheckEntry.end); let message; + let overlapStart; + let overlapEnd; // is there an overlap? if ((crossCheckStart < myEnd && myStart < crossCheckEnd) && (crossCheckEntry.user.id === myUserId)) { // find overlapping inteval - const overlapStart = moment.max(myStart, crossCheckStart); - const overlapEnd = moment.min(crossCheckEnd, myEnd); + overlapStart = moment.max(myStart, crossCheckStart); + overlapEnd = moment.min(crossCheckEnd, myEnd); message = { user: myUserName, @@ -160,8 +162,8 @@ function processSchedules(allSchedules, days = [], cb) { }); } - if (overlap && !duplicities.myUserName.includes(crossCheckEntry.start)) { - duplicities.myUserName.push(crossCheckEntry.start); + if (overlap && !duplicities[myUserName].includes(overlapStart.toISOString())) { + duplicities[myUserName].push(overlapStart.toISOString()); messages.push(message); } });