Skip to content

Commit

Permalink
refactor: ♻️ 프론트 테스트용 임시 함수 리팩토링
Browse files Browse the repository at this point in the history
- #405

refactor: ♻️ type-only import 추가

- #405
  • Loading branch information
niamu01 committed Dec 27, 2023
1 parent d81a908 commit 8e35eea
Showing 1 changed file with 4 additions and 34 deletions.
38 changes: 4 additions & 34 deletions app/src/follow/follow.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
} from 'src/database/mongoose/database.mongoose.query';
import { CursusUserService } from '../api/cursusUser/cursusUser.service';
import { follow } from './db/follow.database.schema';
import { FollowList, FollowResult } from './model/follow.model';
import type { FollowList, FollowResult } from './model/follow.model';

@Injectable()
export class FollowService {
Expand All @@ -28,41 +28,11 @@ export class FollowService {
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);

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

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

return {
message: 'OK',
userId: fromId!,
followId: toId!,
};
return await this.unfollowUser(userId!, to);
}
return { message: 'fail' };
}
Expand Down

0 comments on commit 8e35eea

Please sign in to comment.