Moved approval fields to group subdoc

This commit is contained in:
Keith Holliday
2016-10-22 13:07:26 -05:00
parent d798ebadfe
commit 3ec3722038
7 changed files with 26 additions and 21 deletions

View File

@@ -316,13 +316,13 @@ api.scoreTask = {
if (!task) throw new NotFound(res.t('taskNotFound'));
if (task.requiresApproval && !task.approved) {
if (task.approvalRequested) {
if (task.group.requiresApproval && !task.group.approved) {
if (task.group.approvalRequested) {
throw new NotAuthorized(res.t('taskRequiresApproval'));
}
task.approvalRequested = true;
task.approvalRequestedDate = new Date();
task.group.approvalRequested = true;
task.group.approvalRequestedDate = new Date();
let group = await Group.getGroup({user, groupId: task.group.id, fields: requiredGroupFields});
let groupLeader = await User.findById(group.leader); // Use this method so we can get access to notifications

View File

@@ -221,9 +221,9 @@ api.approveTask = {
if (group.leader !== user._id) throw new NotAuthorized(res.t('onlyGroupLeaderCanEditTasks'));
task.approvedDate = new Date();
task.approvingUser = user._id;
task.approved = true;
task.group.approvedDate = new Date();
task.group.approvingUser = user._id;
task.group.approved = true;
assignedUser.addNotification('GROUP', {message: res.t('yourTaskHasBeenApproved')});
@@ -264,8 +264,8 @@ api.getGroupApprovals = {
let approvals = await Tasks.Task.find({
'group.id': groupId,
approved: false,
approvalRequested: true,
'group.approved': false,
'group.approvalRequested': true,
}).exec();
res.respond(200, approvals);