From df7a1f163b62cfcbea1923404c5291a71ef831e6 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sat, 18 Jul 2020 16:59:18 -0500 Subject: [PATCH] refactor: friendship as ids --- src/server/models/user.model.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/server/models/user.model.js b/src/server/models/user.model.js index e502d10..7e499dd 100644 --- a/src/server/models/user.model.js +++ b/src/server/models/user.model.js @@ -49,15 +49,10 @@ class User extends BaseModel { }, }); const friendList = await Promise.all( - friendships.map(async ({adderId, addeeId, state}) => { - const otherId = adderId === this.id ? addeeId : adderId; - const user = await User.findByPk(otherId); - return { - id: user.id, - redditUsername: user.redditUsername, - state, - }; - }), + friendships.map(async ({adderId, addeeId, state}) => ([ + adderId === this.id ? addeeId : adderId, + state, + ])), ); return friendList.reduce((r, friend) => ({...r, [friend.id]: friend}), {}); }