Added authorization pieces + test functions

This commit is contained in:
Wyatt Johnson
2016-11-22 17:15:14 -07:00
parent 32d715e784
commit 325162cb3e
17 changed files with 190 additions and 153 deletions
+14 -2
View File
@@ -41,7 +41,7 @@ ActionSchema.statics.findByItemIdArray = function(item_ids) {
* Returns summaries of actions for an array of ids
* @param {String} ids array of user identifiers (uuid)
*/
ActionSchema.statics.getActionSummaries = function(item_ids) {
ActionSchema.statics.getActionSummaries = function(item_ids, current_user_id = '') {
return Action.aggregate([
{
@@ -71,6 +71,18 @@ ActionSchema.statics.getActionSummaries = function(item_ids) {
// just grabbing the last instance of the item type here.
item_type: {
$last: '$item_type'
},
current_user: {
$max: {
$cond: {
if: {
$eq: ['$user_id', current_user_id],
},
then: '$$CURRENT',
else: null
}
}
}
}
},
@@ -89,7 +101,7 @@ ActionSchema.statics.getActionSummaries = function(item_ids) {
item_type: '$item_type',
// set the current user to false here
current_user: {$literal: false}
current_user: '$current_user'
}
}
])