bastienrobert/la-ferme

View on GitHub
packages/server/app/helpers/getChosenCard.ts

Summary

Maintainability
A
0 mins
Test Coverage
import { RoundChoice } from '@la-ferme/shared/typings'
import { getCard, roundChoiceToCardType } from '@la-ferme/shared/data/cards'

import Round from '@/app/models/Round'

interface Cards {
  civil: string
  uncivil: string
}

export const getChosenCard = (cards: Cards, choice: RoundChoice) => {
  const type = roundChoiceToCardType[choice]
  return getCard(cards[type])
}

export const getChosenCardFromRound = (round: Round) => {
  return getChosenCard(
    {
      civil: round.civilCard,
      uncivil: round.uncivilCard
    },
    round.choice
  )
}