Skip to content

Fix: update timeline in es milestones cascade #380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Sep 10, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 7 additions & 28 deletions src/events/milestones/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,35 +82,14 @@ const milestoneUpdatedHandler = Promise.coroutine(function* (logger, msg, channe
});
}

// if (data.original.order !== data.updated.order) {
// const milestoneWithSameOrder =
// _.find(milestones, milestone => milestone.id !== data.updated.id && milestone.order === data.updated.order);
// if (milestoneWithSameOrder) {
// // Increase the order from M to K: if there is an item with order K,
// // orders from M+1 to K should be made M to K-1
// if (data.original.order < data.updated.order) {
// _.each(milestones, (single) => {
// if (single.id !== data.updated.id
// && (data.original.order + 1) <= single.order
// && single.order <= data.updated.order) {
// single.order -= 1; // eslint-disable-line no-param-reassign
// }
// });
// } else {
// // Decrease the order from M to K: if there is an item with order K,
// // orders from K to M-1 should be made K+1 to M
// _.each(milestones, (single) => {
// if (single.id !== data.updated.id
// && data.updated.order <= single.order
// && single.order <= (data.original.order - 1)) {
// single.order += 1; // eslint-disable-line no-param-reassign
// }
// });
// }
// }
// }
let updatedTimeline = doc._source; // eslint-disable-line no-underscore-dangle
// if timeline has been modified during milestones updates
if (data.cascadedUpdates && data.cascadedUpdates.timeline && data.cascadedUpdates.timeline.updated) {
// merge updated timeline with the object in ES index, the same way as we do when updating timeline in ES using timeline endpoints
updatedTimeline = _.merge(doc._source, data.cascadedUpdates.timeline.updated); // eslint-disable-line no-underscore-dangle
}

const merged = _.assign(doc._source, { milestones }); // eslint-disable-line no-underscore-dangle
const merged = _.assign(updatedTimeline, { milestones });
yield eClient.update({
index: ES_TIMELINE_INDEX,
type: ES_TIMELINE_TYPE,
Expand Down