<commit_before>'use strict';

var express = require('express');
var validator = require('validator');
var email = require('../../email');
var models = require('../../models');
var auth = require('../../auth');
var router = express.Router();
var User = models.User;
var Project = models.Project;

router.use(auth.requireUserOr401);

router.route('/:provider/:id')

/**
 * @api {put} /:provider/:id Update Provider Account
 * @apiDescription Updates a provider account for the _active_ user (the API user).
 * @apiName UpdateAccount
 * @apiGroup Account
 * @apiVersion 1.0.0
 *
 * @apiParam {String} provider Type of provider, e.g. github
 * @apiParam {Number} id Unique provider identification
 */
  .put(function (req, res) {
    var accounts = req.user.accounts;
    var provider = req.params.provider;
    var id = req.params.id;

    for (var i = 0; i < accounts.length; i++) {
      if (accounts[i].provider === provider &&
        accounts[i].id === id) {
        // TODO validate these accounts
        accounts[i] = req.body;

        return User.update({_id: req.user._id}, {$set: {accounts: accounts}}, function (err, effected) {
          if (effected !== 1) {
            return res.status(500).send('Failed to save one user');
          }

          res.sendStatus(200);
        });
      }
    }

    accounts.push(req.body);

    User.update({_id: req.user._id}, {$set: {accounts: accounts}}, function (err, effected) {
      if (effected !== 1) {<commit_msg>Fix mongoose usage<commit_after>'use strict';

var auth = require('../../auth');
var debug = require('debug')('strider:api:account');
var email = require('../../email');
var express = require('express');
var models = require('../../models');
var Project = models.Project;
var router = express.Router();
var User = models.User;
var validator = require('validator');

router.use(auth.requireUserOr401);

router.route('/:provider/:id')

/**
 * @api {put} /:provider/:id Update Provider Account
 * @apiDescription Updates a provider account for the _active_ user (the API user).
 * @apiName UpdateAccount
 * @apiGroup Account
 * @apiVersion 1.0.0
 *
 * @apiParam {String} provider Type of provider, e.g. github
 * @apiParam {Number} id Unique provider identification
 */
  .put(function (req, res) {
    var accounts = req.user.accounts;
    var provider = req.params.provider;
    var id = req.params.id;

    for (var i = 0; i < accounts.length; i++) {
      if (accounts[i].provider === provider &&
        accounts[i].id === id) {
        // TODO validate these accounts
        accounts[i] = req.body;

        return User.update({_id: req.user._id}, {$set: {accounts: accounts}}, function (err) {
          if (err) {
            debug(err);
            return res.status(500).send('Failed to save one user');
          }

          res.sendStatus(200);
        });
      }
    }

    accounts.push(req.body);

    User.update({_id: req.user._id}, {$set: {accounts: accounts}}, function (err) {
      if (err) {
        debug(err);
{'fraction_non_alphanumeric': 0.16633399866932802, 'fraction_numerical': 0.009314703925482368, 'mean_word_length': 2.900129701686122, 'pattern_counts': {'":': 0, '<': 5, '<?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': '2455378', 'n_tokens_mistral': 932, 'n_tokens_neox': 908, 'n_words': 257}