mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 22:27:26 +01:00
Moved approval fields to group subdoc
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user