From 8e35eea323a6f107cb26acf0e8e7025cbe7c2335 Mon Sep 17 00:00:00 2001 From: niamu01 Date: Sat, 16 Dec 2023 20:08:54 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20:recycle:=20=ED=94=84=EB=A1=A0?= =?UTF-8?q?=ED=8A=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9=20=EC=9E=84?= =?UTF-8?q?=EC=8B=9C=20=ED=95=A8=EC=88=98=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - #405 refactor: :recycle: type-only import 추가 - #405 --- app/src/follow/follow.service.ts | 38 ++++---------------------------- 1 file changed, 4 insertions(+), 34 deletions(-) diff --git a/app/src/follow/follow.service.ts b/app/src/follow/follow.service.ts index 1a63c220..f1643f04 100644 --- a/app/src/follow/follow.service.ts +++ b/app/src/follow/follow.service.ts @@ -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 { @@ -28,41 +28,11 @@ export class FollowService { from: string, type: 'follow' | 'unfollow', ): Promise { - 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' }; }