Skip to content

Commit

Permalink
feat: ✨ MakeFollow: 프론트 테스트용 임시 함수 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
niamu01 committed Dec 14, 2023
1 parent 2a19383 commit 5dea62d
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 5 deletions.
14 changes: 12 additions & 2 deletions app/src/follow/follow.resolve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ import { FollowResult, FollowUserList } from './model/follow.model';
export class FollowResolver {
constructor(private readonly followService: FollowService) {}

// 프론트 테스트용 임시 함수
@Mutation((_returns) => FollowResult)
async MakeFollow(
@Args('to') to: string,
@Args('from') from: string,
@Args('type') type: 'follow' | 'unfollow',
): Promise<typeof FollowResult> {
return await this.followService.MakeFollowUser(to, from, type);
}

@Mutation((_returns) => FollowResult)
async followUser(
@MyUserId() userId: number,
Expand All @@ -21,11 +31,11 @@ export class FollowResolver {
}

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

@Mutation((_returns) => FollowUserList)
Expand Down
51 changes: 49 additions & 2 deletions app/src/follow/follow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,51 @@ export class FollowService {
private readonly cursusUserService: CursusUserService,
) {}

// 프론트 테스트용 임시 함수
async MakeFollowUser(
to: string,
from: string,
type: 'follow' | 'unfollow',
): Promise<typeof FollowResult> {
const toId = await this.cursusUserService
.findOneAndLean({
filter: { 'user.login': to },
})
.then((following) => following?.user.id);

const fromId = await this.cursusUserService
.findOneAndLean({
filter: { 'user.login': from },
})
.then((following) => following?.user.id);

if (type === 'follow') {
await this.followModel
.create({ userId: fromId, followId: toId })
.then((result) => result.toObject());

return {
message: 'OK',
userId: fromId!,
followId: toId!,
};
} else if (type === 'unfollow') {
await this.followModel
.deleteOne({
userId: fromId,
followId: toId,
})
.then((result) => result.deletedCount);

return {
message: 'OK',
userId: fromId!,
followId: toId!,
};
}
return { message: 'fail' };
}

// input으로 들어온 유저를 팔로우 함
async followUser(
followerId: number,
Expand All @@ -36,7 +81,9 @@ export class FollowService {
followId: following,
});

if (!following || followerId === following || !alreadyFollow) {
console.log(alreadyFollow.length);

if (!following || followerId === following || alreadyFollow.length) {
return { message: 'fail' };
}

Expand All @@ -53,7 +100,7 @@ export class FollowService {

// input으로 들어온 유저를 언팔로우 함
// todo: unfollow 성공도 같은걸 (상태) 반환해서 이름 다시 지어야함
async unFollowUser(
async unfollowUser(
followerId: number,
followingLogin: string,
): Promise<typeof FollowResult> {
Expand Down
3 changes: 2 additions & 1 deletion app/src/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -646,8 +646,9 @@ type Mutation {
refreshToken(refreshToken: String!): LoginSuccess!
logout: Int!
deleteAccount: Int!
MakeFollow(to: String!, from: String!, type: String!): FollowResult!
followUser(login: String!): FollowResult!
unFollowUser(login: String!): FollowResult!
unfollowUser(login: String!): FollowResult!
getFollowerList(login: String!): FollowUserList!
getFollowingList(login: String!): FollowUserList!
}
Expand Down

0 comments on commit 5dea62d

Please sign in to comment.