mirror of
https://github.com/wassname/talk.git
synced 2026-09-09 11:38:08 +08:00
Addressing but where flag increases like count.
This commit is contained in:
+5
-7
@@ -45,25 +45,23 @@ ActionSchema.statics.getActionSummaries = function(item_ids) {
|
||||
return ActionSchema.statics.findByItemIdArray(item_ids).then((rawActions) => {
|
||||
// Create an object with a count of each action type for each item
|
||||
const actionSummaries = rawActions.reduce((actionObj, action) => {
|
||||
if (!actionObj[action.item_id]) {
|
||||
actionObj[action.item_id] = {
|
||||
if (!actionObj[`${action.item_id}_${action.action_type}`]) {
|
||||
actionObj[`${action.item_id}_${action.action_type}`] = {
|
||||
id: action.id,
|
||||
item_id: action.item_id,
|
||||
item_type: action.item_type,
|
||||
action_type: action.action_type,
|
||||
count: 1,
|
||||
current_user: false //Update this later when we have authentication
|
||||
};
|
||||
} else {
|
||||
actionObj[action.item_id].count ++;
|
||||
actionObj[`${action.item_id}_${action.action_type}`].count ++;
|
||||
}
|
||||
return actionObj;
|
||||
}, {});
|
||||
|
||||
// Return an array extracted from the actionSummaries object
|
||||
return Object.keys(actionSummaries).reduce((actions, key) => {
|
||||
let actionSummary = actionSummaries[key];
|
||||
actionSummary.item_id = key;
|
||||
actions.push(actionSummary);
|
||||
actions.push(actionSummaries[key]);
|
||||
return actions;
|
||||
}, []);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user