Skip to content

Commit

Permalink
[HOTFIX] 재투표 삭제처리 (#180)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyY00n authored Jul 3, 2023
1 parent 88eb604 commit fe463bb
Showing 1 changed file with 11 additions and 17 deletions.
28 changes: 11 additions & 17 deletions src/services/ballotService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,27 @@ 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,
guestId: command.guestId
});

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,
Expand Down

0 comments on commit fe463bb

Please sign in to comment.