Skip to content

Commit

Permalink
refactor: ♻️ list 쿼리에도 sort의 defaultvalue 추가
Browse files Browse the repository at this point in the history
- #406

fix: 🐛 following 관련 함수에서 사용한 follower -> following 수정

- #406

fix: 🐛 파일명 수정 resolve -> resolver

style: 🎨 변수 선언 시 필요 없는 타입 어노테이션 제거

- #406

fix: 🐛 필요없는 if 검사 삭제

- #406

fix: 🐛 변수 대입을 안하고 있었던 부분 수정 (...)
  • Loading branch information
niamu01 committed Feb 20, 2024
1 parent 4403cee commit 877225e
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 17 deletions.
2 changes: 1 addition & 1 deletion app/src/follow/follow.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { MongooseModule } from '@nestjs/mongoose';
import { CursusUserModule } from 'src/api/cursusUser/cursusUser.module';
import { PaginationCursorModule } from 'src/pagination/cursor/pagination.cursor.module';
import { FollowSchema, follow } from './db/follow.database.schema';
import { FollowResolver } from './follow.resolve';
import { FollowResolver } from './follow.resolver';
import { FollowService } from './follow.service';

@Module({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ export class FollowResolver {
@MyUserId() userId: number,
@Args('target') target: string,
@Args('limit', { defaultValue: 3 }) limit: number,
@Args('sortOrder', { type: () => FollowSortOrder })
@Args('sortOrder', {
type: () => FollowSortOrder,
defaultValue: FollowSortOrder.FOLLOW_AT_DESC,
})
sortOrder: FollowSortOrder,
): Promise<FollowListWithCount> {
const targetId = await this.followService.userIdByLogin(target);
Expand Down Expand Up @@ -111,7 +114,10 @@ export class FollowResolver {
@MyUserId() userId: number,
@Args('target') target: string,
@Args('limit', { defaultValue: 3 }) limit: number,
@Args('sortOrder', { type: () => FollowSortOrder })
@Args('sortOrder', {
type: () => FollowSortOrder,
defaultValue: FollowSortOrder.FOLLOW_AT_DESC,
})
sortOrder: FollowSortOrder,
): Promise<FollowListWithCount> {
const targetId = await this.followService.userIdByLogin(target);
Expand Down
22 changes: 10 additions & 12 deletions app/src/follow/follow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export class FollowService {
.sort(followSort(sortOrder))
.limit(limit);

const followerUserPreview: UserPreview[] = await Promise.all(
const followerUserPreview = await Promise.all(
follower.map(async (follower) => {
const userPreview =
await this.cursusUserService.findOneUserPreviewAndLean({
Expand Down Expand Up @@ -211,7 +211,7 @@ export class FollowService {
.sort(followSort(sortOrder))
.limit(limit);

const followingUserPreview: UserPreview[] = await Promise.all(
const followingUserPreview = await Promise.all(
following.map(async (following) => {
const userPreview =
await this.cursusUserService.findOneUserPreviewAndLean({
Expand All @@ -235,7 +235,7 @@ export class FollowService {
): Promise<FollowListPaginated> {
const targetId = await this.userIdByLogin(target);

const totalCount = await this.followerCount(targetId);
const totalCount = await this.followingCount(targetId);

const aggregate = this.followModel.aggregate<follow>();
const filter: FilterQuery<follow> = {};
Expand Down Expand Up @@ -301,10 +301,12 @@ export class FollowService {

let isFollowing: boolean | undefined = undefined;

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

return isFollowing;
}
Expand All @@ -314,10 +316,6 @@ export class FollowService {
userPreview: UserPreview[],
): Promise<FollowList[]> {
const followList = userPreview.map(async (user) => {
if (!user) {
throw new NotFoundException();
}

let isFollowing: boolean | undefined = undefined;

if (userId !== user.id) {
Expand All @@ -332,7 +330,7 @@ export class FollowService {
return { isFollowing, user };
});

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

private generateEmptyPage(): FollowListPaginated {
Expand Down
4 changes: 2 additions & 2 deletions app/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,9 @@ type Query {
getSetting: Setting!
getExpTable: [ExpTable!]!
getFollowStatus(target: String!): Boolean
getFollowerList(target: String!, limit: Int! = 3, sortOrder: FollowSortOrder!): FollowListWithCount!
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!): FollowListWithCount!
getFollowingList(target: String!, limit: Int! = 3, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): FollowListWithCount!
getFollowingPaginated(after: String, first: Int! = 20, target: String!, sortOrder: FollowSortOrder! = FOLLOW_AT_DESC): FollowListPaginated!
}

Expand Down

0 comments on commit 877225e

Please sign in to comment.