From fe463bbb2678e4501f379408f8866362923f90d6 Mon Sep 17 00:00:00 2001 From: kyY00n Date: Tue, 4 Jul 2023 01:49:18 +0900 Subject: [PATCH] =?UTF-8?q?[HOTFIX]=20=EC=9E=AC=ED=88=AC=ED=91=9C=20?= =?UTF-8?q?=EC=82=AD=EC=A0=9C=EC=B2=98=EB=A6=AC=20(#180)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/services/ballotService.ts | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/src/services/ballotService.ts b/src/services/ballotService.ts index 6814324..26180d7 100644 --- a/src/services/ballotService.ts +++ b/src/services/ballotService.ts @@ -13,6 +13,14 @@ const createBallotResult = async (command: CreateBallotResultDto) => { throw new IllegalArgumentException('올바르지 않은 투표 주제 id 입니다.'); } + const ballotItem = await BallotItem.findById(command.ballotItemId); + if ( + !ballotItem || + ballotItem.ballotTopicId.toString() !== ballotTopic._id.toString() + ) { + throw new IllegalArgumentException('올바르지 않은 투표 항목 id 입니다.'); + } + const alreadyBallotResult = await BallotResult.findOne({ ballotTopicId: command.ballotTopicId, userId: command.userId, @@ -20,26 +28,12 @@ const createBallotResult = async (command: CreateBallotResultDto) => { }); if (alreadyBallotResult) { - if ( - alreadyBallotResult.ballotItemId.toString() == - command.ballotItemId.toString() - ) { - throw new IllegalArgumentException('이미 투표한 항목입니다.'); - } - await BallotResult.findByIdAndUpdate( - { - _id: alreadyBallotResult._id - }, - { ballotItemId: command.ballotItemId } - ); + await BallotResult.deleteOne({ + _id: alreadyBallotResult._id + }); return; } - const ballotItem = await BallotItem.findById(command.ballotItemId); - if (!ballotItem) { - throw new IllegalArgumentException('올바르지 않은 투표 항목 id 입니다.'); - } - const newBallot = new BallotResult({ ballotTopicId: ballotItem.ballotTopicId, ballotItemId: ballotItem._id,