refactor: friendship as ids

This commit is contained in:
cha0s 2020-07-18 16:59:18 -05:00
parent 619292b853
commit df7a1f163b

View File

@ -49,15 +49,10 @@ class User extends BaseModel {
}, },
}); });
const friendList = await Promise.all( const friendList = await Promise.all(
friendships.map(async ({adderId, addeeId, state}) => { friendships.map(async ({adderId, addeeId, state}) => ([
const otherId = adderId === this.id ? addeeId : adderId; adderId === this.id ? addeeId : adderId,
const user = await User.findByPk(otherId);
return {
id: user.id,
redditUsername: user.redditUsername,
state, state,
}; ])),
}),
); );
return friendList.reduce((r, friend) => ({...r, [friend.id]: friend}), {}); return friendList.reduce((r, friend) => ({...r, [friend.id]: friend}), {});
} }