Skip to content

Commit

Permalink
refactor: ♻️ 변수명 수정 및 함수 분리
Browse files Browse the repository at this point in the history
login -> target, FollowListByMe -> FollowList, FollowUserList -> FollowListWithCount, followUser->followLser, cursusUserService에 유저 아이디 찾는 함수 추가, 중복되는 함수 분리

- #405
  • Loading branch information
niamu01 committed Dec 14, 2023
1 parent dcad6f5 commit 386d670
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 137 deletions.
43 changes: 43 additions & 0 deletions app/src/api/cursusUser/cursusUser.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ export class CursusUserService {
return this.cursusUserModel.aggregate<ReturnType>();
}

async getuserIdByLogin(login: string): Promise<number | null> {
const userId = await this.findOneAndLean({
filter: { 'user.login': login },
}).then((user) => user?.user.id);

if (!userId) {
return null;
}

return userId;
}

async findAllAndLean(
queryArgs?: QueryArgs<cursus_user>,
): Promise<cursus_user[]> {
Expand Down Expand Up @@ -116,6 +128,37 @@ export class CursusUserService {
}));
}

async findOneUserPreviewAndLean(
queryArgs?: Omit<QueryArgs<cursus_user>, 'select'>,
): Promise<UserPreview | null> {
const cursusUsers: {
user: {
id: number;
login: string;
image: {
link?: string;
};
};
} | null = await this.findOneAndLean({
...queryArgs,
select: {
'user.id': 1,
'user.login': 1,
'user.image.link': 1,
},
});

if (!cursusUsers) {
return null;
}

return {
id: cursusUsers.user.id,
login: cursusUsers.user.login,
imgUrl: cursusUsers.user.image.link,
};
}

async userFullProfile(
filter?: FilterQuery<cursus_user>,
): Promise<UserFullProfile[]> {
Expand Down
1 change: 0 additions & 1 deletion app/src/follow/follow.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { FollowService } from './follow.service';
CursusUserModule,
],
providers: [FollowResolver, FollowService],
//exports: [FollowService],
})
// eslint-disable-next-line
export class FollowModule {}
40 changes: 23 additions & 17 deletions app/src/follow/follow.resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MyUserId } from 'src/auth/myContext';
import { StatAuthGuard } from 'src/auth/statAuthGuard';
import { HttpExceptionFilter } from 'src/http-exception.filter';
import { FollowService } from './follow.service';
import { FollowResult, FollowUserList } from './model/follow.model';
import { FollowListWithCount, FollowResult } from './model/follow.model';

@UseFilters(HttpExceptionFilter)
@UseGuards(StatAuthGuard)
Expand All @@ -26,44 +26,50 @@ export class FollowResolver {
@Mutation((_returns) => FollowResult)
async followUser(
@MyUserId() userId: number,
@Args('login') login: string,
@Args('target') target: string,
): Promise<typeof FollowResult> {
return await this.followService.followUser(userId, login);
return await this.followService.followUser(userId, target);
}

@Mutation((_returns) => FollowResult)
async unfollowUser(
@MyUserId() userId: number,
@Args('login') login: string,
@Args('target') target: string,
): Promise<typeof FollowResult> {
return await this.followService.unfollowUser(userId, login);
return await this.followService.unfollowUser(userId, target);
}

@Mutation((_returns) => FollowUserList)
@Mutation((_returns) => FollowListWithCount)
async getFollowerList(
@MyUserId() userId: number,
@Args('login') login: string,
): Promise<FollowUserList> {
const followUser = await this.followService.getFollowerList(userId, login);
const count = await this.followService.getFollowerCount(login);
@Args('target') target: string,
): Promise<FollowListWithCount> {
const followerList = await this.followService.getFollowerList(
userId,
target,
);
const count = await this.followService.getFollowerCount(target);

return {
count,
followUser,
followList: followerList,
};
}

@Mutation((_returns) => FollowUserList)
@Mutation((_returns) => FollowListWithCount)
async getFollowingList(
@MyUserId() userId: number,
@Args('login') login: string,
): Promise<FollowUserList> {
const followUser = await this.followService.getFollowingList(userId, login);
const count = await this.followService.getFollowingCount(login);
@Args('target') target: string,
): Promise<FollowListWithCount> {
const followingList = await this.followService.getFollowingList(
userId,
target,
);
const count = await this.followService.getFollowingCount(target);

return {
count,
followUser,
followList: followingList,
};
}
}
Loading

0 comments on commit 386d670

Please sign in to comment.