<commit_before>Meteor.methods({
  newGame: function(postAttributes) {
    var user = Meteor.user();
    //, postWithSameLink = Players.findOne({firstName: postAttributes.firstName});

    // ensure the user is logged in
    if (!user) {
      throw new Meteor.Error(401, "You need to login to add a team");
    }

     check(postAttributes, {
      teamId:       String,
      gameDateTime: Date,
      leagueName:   String,
      seasonName:   String,
      opponentName: String,
      fieldName:    String,
      fieldUrl:     String,
      homeTeam:     String
    });

    // ensure the post has a name
    if (!postAttributes.gameDateTime) {
      throw new Meteor.Error(422, "Please provide a Game Date/Time");
    }

    // pick out the whitelisted keys
    // Those on the list will be accepted, approved or recognized
    var game = _.extend(_.pick(postAttributes,
      'teamId',
      'gameDateTime',
      'leagueName',
      'seasonName',
      'opponentName',
      'fieldName',
      'fieldUrl',
      'homeTeam'), {

      createdBy: user._id,
      author: user.username,
      gameCreated: true,
      submitted: new Date().getTime()
    });


    var gameId = Games.insert(game);

    return gameId;
  },
  newPlayerInfo: function(postAttributes) {
    var user = Meteor.user();

    // ensure the user is logged in
    if (!user) {
      throw new Meteor.Error(401, "You need to login to add a team");
    }

    var allGamePositions = {
      playerGameInfo: postAttributes,
      lastModified: new Date().getTime()
    }

    Games.insert(allGamePositions);
  },
  updateStarter: function(gameId, postAttributes) {
    var user = Meteor.user();

    // ensure the user is logged in
    if (!user) {
      throw new Meteor.Error(401, "You need to login to add a team");
    }

    console.log(postAttributes.playerFullName);

    /*=================================================
    =            dynamic object properties            =
    =================================================*/
    // had problems and spent hours on this
    // if you need to dynamically change an object property
    // you need to create and object and use this syntax 
    // myObj["string" + variable + "string"] = something
    //  I do that for two keys below
    var playerMatchObj = {};
    playerMatchObj._id = gameId;<commit_msg>add checks for security<commit_after>Meteor.methods({
  newGame: function(postAttributes) {
    var user = Meteor.user();
    //, postWithSameLink = Players.findOne({firstName: postAttributes.firstName});

    // ensure the user is logged in
    if (!user) {
      throw new Meteor.Error(401, "You need to login to add a team");
    }

     check(postAttributes, {
      teamId:       String,
      gameDateTime: Date,
      opponentName: String,
      fieldName:    String,
      fieldUrl:     String,
      homeTeam:     Boolean
    });

    // ensure the post has a name
    if (!postAttributes.gameDateTime) {
      throw new Meteor.Error(422, "Please provide a Game Date/Time");
    }

    // pick out the whitelisted keys
    // Those on the list will be accepted, approved or recognized
    var game = _.extend(_.pick(postAttributes,
      'teamId',
      'gameDateTime',
      'opponentName',
      'fieldName',
      'fieldUrl',
      'homeTeam'), {

      leagueName: "NA",
      seasonName: "NA",
      createdBy: user._id,
      author: user.username,
      gameCreated: true,
      submitted: new Date().getTime()
    });

    var gameId = Games.insert(game);

    return gameId;
  },
  newPlayerInfo: function(postAttributes) {
    var user = Meteor.user();

    // ensure the user is logged in
    if (!user) {
      throw new Meteor.Error(401, "You need to login to add a team");
    }

    var allGamePositions = {
      playerGameInfo: postAttributes,
      lastModified: new Date().getTime()
    }

    Games.insert(allGamePositions);
  },
  updateStarter: function(gameId, postAttributes) {
    var user = Meteor.user();

    // ensure the user is logged in
    if (!user) {
      throw new Meteor.Error(401, "You need to login to add a team");
    }
    //console.log(postAttributes);
    check(gameId, String);
    check(postAttributes, {
      playerDivNum: String,
      playerId: String,
      playerFullName: String
    });

    /*=================================================
    =            dynamic object properties            =
    =================================================*/
    // had problems and spent hours on this
    // if you need to dynamically change an object property
    // you need to create and object and use this syntax 
    // myObj["string" + variable + "string"] = something
    //  I do that for two keys below
    var playerMatchObj = {};
    playerMatchObj._id = gameId;
{'fraction_non_alphanumeric': 0.14476987447698744, 'fraction_numerical': 0.00502092050209205, 'mean_word_length': 2.464492753623188, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7354382', 'n_tokens_mistral': 1390, 'n_tokens_neox': 1326, 'n_words': 415}