Added streak to export of challenge tasks (#9625)

* Added streak to export of challenge tasks

* Fixed tests
This commit is contained in:
Keith Holliday
2017-12-11 11:39:43 -06:00
committed by GitHub
parent 507133c76e
commit 2dfcda068b
2 changed files with 10 additions and 8 deletions

View File

@@ -64,11 +64,11 @@ describe('GET /challenges/:challengeId/export/csv', () => {
let sortedMembers = _.sortBy([members[0], members[1], members[2], groupLeader], '_id'); let sortedMembers = _.sortBy([members[0], members[1], members[2], groupLeader], '_id');
let splitRes = res.split('\n'); let splitRes = res.split('\n');
expect(splitRes[0]).to.equal('UUID,name,Task,Value,Notes,Task,Value,Notes'); expect(splitRes[0]).to.equal('UUID,name,Task,Value,Notes,Streak,Task,Value,Notes,Streak');
expect(splitRes[1]).to.equal(`${sortedMembers[0]._id},${sortedMembers[0].profile.name},habit:Task 1,0,,todo:Task 2,0,`); expect(splitRes[1]).to.equal(`${sortedMembers[0]._id},${sortedMembers[0].profile.name},habit:Task 1,0,,0,todo:Task 2,0,,0`);
expect(splitRes[2]).to.equal(`${sortedMembers[1]._id},${sortedMembers[1].profile.name},habit:Task 1,0,,todo:Task 2,0,`); expect(splitRes[2]).to.equal(`${sortedMembers[1]._id},${sortedMembers[1].profile.name},habit:Task 1,0,,0,todo:Task 2,0,,0`);
expect(splitRes[3]).to.equal(`${sortedMembers[2]._id},${sortedMembers[2].profile.name},habit:Task 1,0,,todo:Task 2,0,`); expect(splitRes[3]).to.equal(`${sortedMembers[2]._id},${sortedMembers[2].profile.name},habit:Task 1,0,,0,todo:Task 2,0,,0`);
expect(splitRes[4]).to.equal(`${sortedMembers[3]._id},${sortedMembers[3].profile.name},habit:Task 1,0,,todo:Task 2,0,`); expect(splitRes[4]).to.equal(`${sortedMembers[3]._id},${sortedMembers[3].profile.name},habit:Task 1,0,,0,todo:Task 2,0,,0`);
expect(splitRes[5]).to.equal(''); expect(splitRes[5]).to.equal('');
}); });
}); });

View File

@@ -555,7 +555,7 @@ api.exportChallengeCsv = {
'challenge.id': challengeId, 'challenge.id': challengeId,
userId: {$exists: true}, userId: {$exists: true},
}).sort({userId: 1, text: 1}) }).sort({userId: 1, text: 1})
.select('userId type text value notes') .select('userId type text value notes streak')
.lean().exec(), .lean().exec(),
]); ]);
@@ -570,7 +570,9 @@ api.exportChallengeCsv = {
index++; index++;
} }
resArray[index].push(`${task.type}:${task.text}`, task.value, task.notes); const streak = task.streak || 0;
resArray[index].push(`${task.type}:${task.text}`, task.value, task.notes, streak);
}); });
// The first row is going to be UUID name Task Value Notes repeated n times for the n challenge tasks // The first row is going to be UUID name Task Value Notes repeated n times for the n challenge tasks
@@ -578,7 +580,7 @@ api.exportChallengeCsv = {
return result.concat(array); return result.concat(array);
}, []).sort(); }, []).sort();
resArray.unshift(['UUID', 'name']); resArray.unshift(['UUID', 'name']);
_.times(challengeTasks.length, () => resArray[0].push('Task', 'Value', 'Notes')); _.times(challengeTasks.length, () => resArray[0].push('Task', 'Value', 'Notes', 'Streak'));
res.set({ res.set({
'Content-Type': 'text/csv', 'Content-Type': 'text/csv',