const possibleResponses = require('../../config/options');

module.exports = {
  drawByAllPossibilites(gameCounter) {
    return gameCounter.every((item) => {
      return item > 0;
    });
  },

  drawByOnlyOnePossibility(gameCounter) {
    var optionsCount = 0;
    gameCounter.forEach((item) => {
      if (item) optionsCount++
    });
    return optionsCount === 1;
  },

  giveWinners(gameCounter, users) {
    var winningOption = null;
    if (gameCounter[0] && gameCounter[1]) {
      winningOption = 'scissors';
    } else if (gameCounter[1] && gameCounter[2]) {
      winningOption = 'paper';
    } else {
      winningOption = 'rock';
    }
    const winners = users.filter((item) => {
      return item.response === winningOption;
    });

    return winners;
  },

  processToGameCounter(results) {
    const gameCounter = [];

    possibleResponses.forEach((item) => {
      gameCounter.push(0);
    });

    results.forEach((result) => {
      gameCounter[possibleResponses.indexOf(result.response)]++;
    });

    return gameCounter;
  },

  updateWinners(winners) {
    Game.update({ _id: game._id }, { winners: winners.map(winner => winner.userId) }, (err) => {
      if (err) console.log(err);
    });
  },
};

@@ -1,12 +1,63 @@
+// Models%0Aconst Game = require('../models/game');%0A%0A
 const possib
@@ -1116,16 +1116,22 @@
 Winners(
+game, 
 winners)

fix bug with winners update