Skip to content

Commit 001ef29

Browse files
author
vikasrohit
authored
Merge pull request #154 from topcoder-platform/issue/126
Issue #126
2 parents 2bcc524 + 3215780 commit 001ef29

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/routes/timelines/update.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,22 +57,31 @@ module.exports = [
5757
// Omit deletedAt, deletedBy
5858
updated = _.omit(updatedTimeline.toJSON(), ['deletedAt', 'deletedBy']);
5959

60-
// Update milestones startDate and endDate if necessary
61-
if (original.startDate !== updated.startDate || original.endDate !== updated.endDate) {
60+
// Update milestones startDate and endDate if necessary, if the timeline startDate changed
61+
if (original.startDate.getTime() !== updated.startDate.getTime()) {
6262
return updatedTimeline.getMilestones()
6363
.then((milestones) => {
6464
let startDate = updated.startDate;
65+
66+
// Process milestones in order
6567
const updateMilestonePromises = _.chain(milestones).sortBy('order').map((_milestone) => {
6668
const milestone = _milestone;
69+
70+
// Update if the iterating startDate is different than the saved one
6771
if (milestone.startDate.getTime() !== startDate.getTime()) {
6872
milestone.startDate = startDate;
6973
milestone.updatedBy = req.authUser.userId;
7074
}
75+
76+
// Make sure the endDate is the correct, i.e. for duration = 1 it should be equal to the start date,
77+
// for duration = 2 it should be equal to the next day and so on...
7178
const endDate = moment.utc(milestone.startDate).add(milestone.duration - 1, 'days').toDate();
7279
if (!milestone.endDate || endDate.getTime() !== milestone.endDate.getTime()) {
7380
milestone.endDate = endDate;
7481
milestone.updatedBy = req.authUser.userId;
7582
}
83+
84+
// Next iterated milestone should have as startDate this milestone's endDate plus one day
7685
startDate = moment.utc(milestone.endDate).add(1, 'days').toDate();
7786
return milestone.save();
7887
}).value();

0 commit comments

Comments
 (0)