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

@@ -63,8 +63,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
expect(member.notifications[0].type).to.equal('GROUP');
expect(member.notifications[0].data.message).to.equal(t('yourTaskHasBeenApproved'));
expect(syncedTask.approved).to.be.true;
expect(syncedTask.approvingUser).to.equal(user._id);
expect(syncedTask.approvedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
expect(syncedTask.group.approved).to.be.true;
expect(syncedTask.group.approvingUser).to.equal(user._id);
expect(syncedTask.group.approvedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
});
});

View File

@@ -50,8 +50,8 @@ describe('POST /tasks/:id/score/:direction', () => {
}));
expect(response.message).to.equal(t('taskApprovalHasBeenRequested'));
expect(updatedTask.approvalRequested).to.equal(true);
expect(updatedTask.approvalRequestedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
expect(updatedTask.group.approvalRequested).to.equal(true);
expect(updatedTask.group.approvalRequestedDate).to.be.a('string'); // date gets converted to a string as json doesn't have a Date type
});
it('errors when approval has already been requested', async () => {

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);

View File

@@ -51,6 +51,10 @@ export async function createTasks (req, res, options = {}) {
let taskType = taskData.type;
let newTask = new Tasks[taskType](Tasks.Task.sanitize(taskData));
if (taskData.requiresApproval) {
newTask.group.requiresApproval = true;
}
if (challenge) {
newTask.challenge.id = challenge.id;
} else if (group) {

View File

@@ -938,6 +938,8 @@ schema.methods.syncTask = async function groupSyncTask (taskToSync, user) {
if (orderList.indexOf(matchingTask._id) === -1 && (matchingTask.type !== 'todo' || !matchingTask.completed)) orderList.push(matchingTask._id);
}
matchingTask.group.requiresApproval = taskToSync.group.requiresApproval;
if (!matchingTask.notes) matchingTask.notes = taskToSync.notes; // don't override the notes, but provide it if not provided
if (matchingTask.tags.indexOf(group._id) === -1) matchingTask.tags.push(group._id); // add tag if missing

View File

@@ -69,14 +69,13 @@ export let TaskSchema = new Schema({
broken: {type: String, enum: ['GROUP_DELETED', 'TASK_DELETED', 'UNSUBSCRIBED']},
assignedUsers: [{type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']}],
taskId: {type: String, ref: 'Task', validate: [validator.isUUID, 'Invalid uuid.']},
},
requiresApproval: {type: Boolean, default: false},
approved: {type: Boolean, default: false},
approvedDate: {type: Date},
approvingUser: {type: String, ref: 'User', validate: [validator.isUUID, 'Invalid uuid.']},
approvalRequested: {type: Boolean, default: false},
approvalRequestedDate: {type: Date},
},
reminders: [{
_id: false,