Skip to content

Commit

Permalink
refactor: ♻️ checkFollowingStatus 함수 활용하도록 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Dec 14, 2023
1 parent 693f5e3 commit e0867e1
Showing 1 changed file with 18 additions and 26 deletions.
44 changes: 18 additions & 26 deletions app/src/follow/follow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,10 @@ export class FollowService {
}

// getFollowingList("yeju") -> yeju(target)가 팔로우 하는 사람들
async getFollowingList(me: number, target: string): Promise<FollowList[]> {
async getFollowingList(
userId: number,
target: string,
): Promise<FollowList[]> {
const targetId = await this.cursusUserService.getuserIdByLogin(target);

if (!targetId) {
Expand All @@ -174,39 +177,28 @@ export class FollowService {
filter: { userId: targetId },
});

const followingUserPreview: Promise<UserPreview | null>[] = following.map(
async (following) => {
const followingUserPreview: UserPreview[] = await Promise.all(
following.map(async (following) => {
//target을 팔로우 하는 사람의 preview
return await this.cursusUserService.findOneUserPreviewAndLean({
filter: { 'user.id': following.userId },
});
},
);

const followingList: Promise<FollowList>[] = followingUserPreview.map(
async (following) => {
const user = await following;
const userPreview =
await this.cursusUserService.findOneUserPreviewAndLean({
filter: { 'user.id': following.followId },
});

if (!user) {
if (!userPreview) {
throw new NotFoundException();
}

let isFollowing: boolean = true;

const isFollowed = await this.followModel.find({
userId: me,
followId: user.id,
});

if (!isFollowed) {
isFollowing = false;
}
return userPreview;
}),
);

return { isFollowing, user };
},
const followingList = await this.checkFollowingStatus(
userId,
followingUserPreview,
);

return await Promise.all(followingList);
return followingList;
}

async getFollowerCount(login: string): Promise<number> {
Expand Down

0 comments on commit e0867e1

Please sign in to comment.