Skip to content

Commit

Permalink
[chore] define playerObj type
Browse files Browse the repository at this point in the history
  • Loading branch information
claustra01 committed Dec 17, 2023
1 parent 2de2203 commit fa84782
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
10 changes: 4 additions & 6 deletions src/usecase/functions/calculateRate.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { config } from '../../config/config';
import { Calculate } from '../types/calculate';
import { Player } from '../types/player';
import { PlayerObj } from '../types/player';

const BaseWeightedCoefficient = config.BaseWeightedCoefficient;
const StackWeightedCoefficient = config.StackWeightedCoefficient;
Expand All @@ -19,9 +19,7 @@ const calculateDiff = (calc: Calculate): number => {
);
};

const roundRate = (
playerObj: Record<string, Player>
): Record<string, Player> => {
const roundRate = (playerObj: PlayerObj): PlayerObj => {
Object.values(playerObj).forEach((player) => {
player.currentRate = Math.round(player.currentRate);
player.maxRate = Math.max(player.currentRate, player.maxRate);
Expand All @@ -31,9 +29,9 @@ const roundRate = (
};

export const calculateRate = (
playerObj: Record<string, Player>,
playerObj: PlayerObj,
calcList: Calculate[]
): Record<string, Player> => {
): PlayerObj => {
let gameCount = calcList[0].gameId;
calcList.forEach((calc) => {
if (calc.gameId !== gameCount) {
Expand Down
8 changes: 3 additions & 5 deletions src/usecase/functions/makeObject.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import { Player } from '../types/player';
import { Player, PlayerObj } from '../types/player';

export const makePlayerObject = (
playerList: Player[]
): Record<string, Player> => {
const playerObj: Record<string, Player> = {};
export const makePlayerObject = (playerList: Player[]): PlayerObj => {
const playerObj: PlayerObj = {};
playerList.forEach((player) => {
playerObj[player.playerName] = player;
});
Expand Down
2 changes: 2 additions & 0 deletions src/usecase/types/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ export type NewPlayer = {
playerName: string;
discordId?: string;
};

export type PlayerObj = Record<string, Player>;

0 comments on commit fa84782

Please sign in to comment.