Added support for scoring group tasks down after approval (#9623)

* Added support for scoring group tasks down after approval

* Fixed lint issues
This commit is contained in:
Keith Holliday
2017-12-04 11:23:47 -06:00
committed by GitHub
parent 72f0b8ed7c
commit 13cdcedcba
4 changed files with 40 additions and 16 deletions

View File

@@ -299,20 +299,22 @@ api.approveTask = {
task.group.approval.approvingUser = user._id;
task.group.approval.approved = true;
assignedUser.addNotification('GROUP_TASK_APPROVED', {
message: res.t('yourTaskHasBeenApproved', {taskText: task.text}),
groupId: group._id,
});
assignedUser.addNotification('SCORED_TASK', {
message: res.t('yourTaskHasBeenApproved', {taskText: task.text}),
scoreTask: task,
});
let managerIds = Object.keys(group.managers);
// Get Managers
const managerIds = Object.keys(group.managers);
managerIds.push(group.leader);
let managers = await User.find({_id: managerIds}, 'notifications').exec(); // Use this method so we can get access to notifications
const managers = await User.find({_id: managerIds}, 'notifications').exec(); // Use this method so we can get access to notifications
// Get task direction
const firstManagerNotifications = managers[0].notifications;
const firstNotificationIndex = findIndex(firstManagerNotifications, (notification) => {
return notification.data.taskId === task._id;
});
let direction = 'up';
if (firstManagerNotifications[firstNotificationIndex]) {
direction = firstManagerNotifications[firstNotificationIndex].direction;
}
// Remove old notifications
let managerPromises = [];
managers.forEach((manager) => {
let notificationIndex = findIndex(manager.notifications, function findNotification (notification) {
@@ -325,6 +327,18 @@ api.approveTask = {
}
});
// Add new notifications to user
assignedUser.addNotification('GROUP_TASK_APPROVED', {
message: res.t('yourTaskHasBeenApproved', {taskText: task.text}),
groupId: group._id,
});
assignedUser.addNotification('SCORED_TASK', {
message: res.t('yourTaskHasBeenApproved', {taskText: task.text}),
scoreTask: task,
direction,
});
managerPromises.push(task.save());
managerPromises.push(assignedUser.save());
await Bluebird.all(managerPromises);