Moved approval to subdoc

This commit is contained in:
Keith Holliday
2016-10-26 16:01:43 -05:00
parent 5b240a1950
commit 59e1de6771
7 changed files with 24 additions and 22 deletions

View File

@@ -63,8 +63,8 @@ describe('POST /tasks/:id/approve/:userId', () => {
expect(member.notifications[0].type).to.equal('GROUP_TASK_APPROVAL'); expect(member.notifications[0].type).to.equal('GROUP_TASK_APPROVAL');
expect(member.notifications[0].data.message).to.equal(t('yourTaskHasBeenApproved')); expect(member.notifications[0].data.message).to.equal(t('yourTaskHasBeenApproved'));
expect(syncedTask.group.approved).to.be.true; expect(syncedTask.group.approval.approved).to.be.true;
expect(syncedTask.group.approvingUser).to.equal(user._id); expect(syncedTask.group.approval.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 expect(syncedTask.group.approval.dateApproved).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(response.message).to.equal(t('taskApprovalHasBeenRequested'));
expect(updatedTask.group.approvalRequested).to.equal(true); expect(updatedTask.group.approval.requested).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 expect(updatedTask.group.approval.requestedDate).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 () => { 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) throw new NotFound(res.t('taskNotFound'));
if (task.group.requiresApproval && !task.group.approved) { if (task.group.approval.required && !task.group.approval.approved) {
if (task.group.approvalRequested) { if (task.group.approval.requested) {
throw new NotAuthorized(res.t('taskRequiresApproval')); throw new NotAuthorized(res.t('taskRequiresApproval'));
} }
task.group.approvalRequested = true; task.group.approval.requested = true;
task.group.approvalRequestedDate = new Date(); task.group.approval.requestedDate = new Date();
let group = await Group.getGroup({user, groupId: task.group.id, fields: requiredGroupFields}); 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 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')); if (group.leader !== user._id) throw new NotAuthorized(res.t('onlyGroupLeaderCanEditTasks'));
task.group.approvedDate = new Date(); task.group.approval.dateApproved = new Date();
task.group.approvingUser = user._id; task.group.approval.approvingUser = user._id;
task.group.approved = true; task.group.approval.approved = true;
assignedUser.addNotification('GROUP_TASK_APPROVAL', {message: res.t('yourTaskHasBeenApproved')}); assignedUser.addNotification('GROUP_TASK_APPROVAL', {message: res.t('yourTaskHasBeenApproved')});
@@ -264,8 +264,8 @@ api.getGroupApprovals = {
let approvals = await Tasks.Task.find({ let approvals = await Tasks.Task.find({
'group.id': groupId, 'group.id': groupId,
'group.approved': false, 'group.approval.approved': false,
'group.approvalRequested': true, 'group.approval.requested': true,
}, 'userId group').exec(); }, 'userId group').exec();
res.respond(200, approvals); res.respond(200, approvals);

View File

@@ -57,7 +57,7 @@ export async function createTasks (req, res, options = {}) {
} else if (group) { } else if (group) {
newTask.group.id = group._id; newTask.group.id = group._id;
if (taskData.requiresApproval) { if (taskData.requiresApproval) {
newTask.group.requiresApproval = true; newTask.group.approval.required = true;
} }
} else { } else {
newTask.userId = user._id; newTask.userId = user._id;

View File

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

View File

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