REFACTOR: Remove _.groupBy

This commit is contained in:
Robin Ward 2020-09-01 14:24:20 -04:00
parent 1265a5f7c0
commit b4444070b3

View File

@ -24,13 +24,17 @@ export default Controller.extend(GrantBadgeController, {
groupedBadges() { groupedBadges() {
const allBadges = this.model; const allBadges = this.model;
var grouped = _.groupBy(allBadges, badge => badge.badge_id); let grouped = {};
allBadges.forEach(b => {
grouped[b.badge_id] = grouped[b.badge_id] || [];
grouped[b.badge_id].push(b);
});
var expanded = []; let expanded = [];
const expandedBadges = allBadges.get("expandedBadges") || []; const expandedBadges = allBadges.get("expandedBadges") || [];
_(grouped).each(function(badges) { Object.values(grouped).forEach(function(badges) {
var lastGranted = badges[0].granted_at; let lastGranted = badges[0].granted_at;
badges.forEach(badge => { badges.forEach(badge => {
lastGranted = lastGranted =
@ -42,7 +46,7 @@ export default Controller.extend(GrantBadgeController, {
return; return;
} }
var result = { let result = {
badge: badges[0].badge, badge: badges[0].badge,
granted_at: lastGranted, granted_at: lastGranted,
badges: badges, badges: badges,
@ -53,10 +57,7 @@ export default Controller.extend(GrantBadgeController, {
expanded.push(result); expanded.push(result);
}); });
return _(expanded) return expanded.sortBy("granted_at").reverse();
.sortBy(group => group.granted_at)
.reverse()
.value();
}, },
actions: { actions: {