Skip to content

Commit

Permalink
refactor: ♻️ followingStatus -> isFollowing 으로 변경 및 중복되는 부분 삭제
Browse files Browse the repository at this point in the history
- #406

style: 🎨 lint
  • Loading branch information
niamu01 committed Feb 20, 2024
1 parent 3c09f68 commit 51b5d47
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 27 deletions.
6 changes: 4 additions & 2 deletions app/src/follow/follow.resolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,13 @@ export class FollowResolver {

@UseGuards(StatAuthGuard)
@Query((_returns) => Boolean, { nullable: true })
async getFollowStatus(
async getIsFollowing(
@MyUserId() userId: number,
@Args('target') target: string,
): Promise<boolean | undefined> {
return await this.followService.followStatus(userId, target);
const targetId = await this.followService.userIdByLogin(target);

return await this.followService.isFollowing(userId, targetId);
}

@UseGuards(StatAuthGuard)
Expand Down
29 changes: 8 additions & 21 deletions app/src/follow/follow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ export class FollowService {
}),
);

return await this.checkFollowingStatus(userId, followerUserPreview);
return await this.checkFollowing(userId, followerUserPreview);
}

async followerPaginated(
Expand All @@ -159,7 +159,6 @@ export class FollowService {

const totalCount = await this.followerCount(targetId);

const aggregate = this.followModel.aggregate<follow>();
const filter: FilterQuery<follow> = {};

if (after) {
Expand Down Expand Up @@ -242,7 +241,7 @@ export class FollowService {
}),
);

return await this.checkFollowingStatus(userId, followingUserPreview);
return await this.checkFollowing(userId, followingUserPreview);
}

async followingPaginated(
Expand All @@ -253,7 +252,6 @@ export class FollowService {

const totalCount = await this.followingCount(targetId);

const aggregate = this.followModel.aggregate<follow>();
const filter: FilterQuery<follow> = {};

if (after) {
Expand Down Expand Up @@ -313,39 +311,28 @@ export class FollowService {
return await this.followModel.countDocuments({ userId, filter });
}

async followStatus(
async isFollowing(
userId: number,
target: string,
targetId: number,
): Promise<boolean | undefined> {
const followId = await this.userIdByLogin(target);

let isFollowing: boolean | undefined = undefined;

if (userId !== followId) {
if (userId !== targetId) {
isFollowing = !!(await this.followModel.findOne({
userId,
followId,
targetId,
}));
}

return isFollowing;
}

async checkFollowingStatus(
async checkFollowing(
userId: number,
userPreview: UserPreview[],
): Promise<FollowList[]> {
const followList = userPreview.map(async (user) => {
let isFollowing: boolean | undefined = undefined;

if (userId !== user.id) {
const isFollowed = await this.followModel.findOne({
userId: userId,
followId: user.id,
});

isFollowing = !!isFollowed;
}
const isFollowing = await this.isFollowing(userId, user.id);

return { isFollowing, user };
});
Expand Down
1 change: 0 additions & 1 deletion app/src/follow/model/follow.model.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Field, ObjectType, createUnionType } from '@nestjs/graphql';
import { UserPreview } from 'src/common/models/common.user.model';
import { CursorPaginated } from 'src/pagination/cursor/models/pagination.cursor.model';
import { follow } from '../db/follow.database.schema';

@ObjectType()
export class FollowList {
Expand Down
4 changes: 2 additions & 2 deletions app/src/page/home/user/models/home.user.model.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Args, ArgsType, Field, ObjectType } from '@nestjs/graphql';
import { IsDateString, IsNumber, Max, Min, NotEquals } from 'class-validator';
import { ArgsType, Field, ObjectType } from '@nestjs/graphql';
import { IsNumber, Max, Min, NotEquals } from 'class-validator';
import { Rate } from 'src/common/models/common.rate.model';
import { UserRank } from 'src/common/models/common.user.model';
import { IntRecord } from 'src/common/models/common.valueRecord.model';
Expand Down
2 changes: 1 addition & 1 deletion app/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,7 @@ type Query {
getEvalLogs(after: String, first: Int! = 20, corrector: String, corrected: String, projectName: String, outstandingOnly: Boolean! = false, imperfectOnly: Boolean! = false, sortOrder: EvalLogSortOrder! = BEGIN_AT_DESC): EvalLogsPaginated!
getSetting: Setting!
getExpTable: [ExpTable!]!
getFollowStatus(target: String!): Boolean
getIsFollowing(target: String!): Boolean
getFollowerList(target: String!, limit: Int! = 3, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): FollowListWithCount!
getFollowerPaginated(after: String, first: Int! = 20, target: String!, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): FollowListPaginated!
getFollowingList(target: String!, limit: Int! = 3, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): FollowListWithCount!
Expand Down

0 comments on commit 51b5d47

Please sign in to comment.