From 2b8d7a2b06fbd3686028af8d060f6dced1d5fad0 Mon Sep 17 00:00:00 2001 From: claustra01 Date: Sun, 17 Dec 2023 23:19:12 +0900 Subject: [PATCH] [add] add medal --- src/adapter/commands/result.ts | 13 ++++++++++--- src/usecase/functions/addMedal.ts | 13 +++++++++++++ 2 files changed, 23 insertions(+), 3 deletions(-) create mode 100644 src/usecase/functions/addMedal.ts diff --git a/src/adapter/commands/result.ts b/src/adapter/commands/result.ts index b802af1..729bdac 100644 --- a/src/adapter/commands/result.ts +++ b/src/adapter/commands/result.ts @@ -1,6 +1,7 @@ import { isValid } from 'date-fns'; import { parse } from 'date-fns/fp'; import { config } from '../../config/config'; +import { addMedal } from '../../usecase/functions/addMedal'; import { calculateRate } from '../../usecase/functions/calculateRate'; import { makePlayerObject } from '../../usecase/functions/makeObject'; import { Calculate, NewCalculate } from '../../usecase/types/calculate'; @@ -137,8 +138,14 @@ export const commandResult = async (args: string[]): Promise => { try { await transactionController.begin(); const playerObj = makePlayerObject(playerList); - const updatedPlayerObj = calculateRate(playerObj, calcList); - Object.values(updatedPlayerObj).forEach(async (player) => { + const rateUpdatedPlayerObj = calculateRate(playerObj, calcList); + const medalUpdatedPlayerObj = addMedal( + rateUpdatedPlayerObj, + playerList[0].playerName, + playerList[1].playerName, + playerList[2].playerName + ); + Object.values(medalUpdatedPlayerObj).forEach(async (player) => { await playerController.update(player); }); await transactionController.commit(); @@ -146,7 +153,7 @@ export const commandResult = async (args: string[]): Promise => { await transactionController.rollback(); return { type: ReplyType.Error, - errorText: `${error}`, + errorText: 'Error: Calculation Failed: use `recalculate` command', }; } diff --git a/src/usecase/functions/addMedal.ts b/src/usecase/functions/addMedal.ts new file mode 100644 index 0000000..266e119 --- /dev/null +++ b/src/usecase/functions/addMedal.ts @@ -0,0 +1,13 @@ +import { PlayerObj } from '../types/player'; + +export const addMedal = ( + playerObj: PlayerObj, + firstWinner: string, + secondWinner: string, + thirdWinner: string +): PlayerObj => { + playerObj[firstWinner].firstWinCount++; + playerObj[secondWinner].secondWinCount++; + playerObj[thirdWinner].thirdWinCount++; + return playerObj; +};