<commit_before>var express = require('express');
var router = express.Router();
var User  = require('./../app/models/user');

router.post('/accountinfo', function(req, res, done) {
  var currentUser = req.body.username;
  new User({username: currentUser})
    .fetch()
    .then(function(user){
      res.json(user);
    });
});

router.post('/accountupdate', function(req, res, done) {
  console.log('updating account');
  var currentUser = req.body.username;
  var data = req.body;
  new User({username: currentUser})
    .fetch()
    .then(function(user) {
      user.save(data)
        .then(function() {
          res.end('updated');
        });
    });
});


router.post('/checkUser', function(req, res, done) {
  // console.log(req.body,'req..body');
  var currentUser = req.body.username;
  // check DB to see if current user has stripe information


  new User({username: currentUser})
    .fetch({
      withRelated: ['invites']
    })
    .then(function(user){

      // console.log('current invites', user.related('invites').models);
      var inviteModels = user.related('invites').models;

      var currentInvites = [];
      for (var i = 0; i < inviteModels.length; i++) {

        if (inviteModels[i].attributes.joined || inviteModels[i].attributes.declined) {
          currentInvites.push(inviteModels[i].attributes.event_id)
        }
      }

      // console.log(currentInvites);
      

     if (user) {

       if (user.attributes.venmoAccessToken && user.attributes.venmoUserId) {
         res.json({
           hasVenmoInfo: true,
           userID: user.attributes.id,
           relatedEventIds: currentInvites
         });

       } else {

         res.json({
           hasVenmoInfo: false,
           userID: user.attributes.id,
           relatedEventIds: currentInvites
         });
       }<commit_msg>Fix exception when user === null<commit_after>var express = require('express');
var router = express.Router();
var User  = require('./../app/models/user');

router.post('/accountinfo', function(req, res, done) {
  var currentUser = req.body.username;
  new User({username: currentUser})
    .fetch()
    .then(function(user){
      res.json(user);
    });
});

router.post('/accountupdate', function(req, res, done) {
  console.log('updating account');
  var currentUser = req.body.username;
  var data = req.body;
  new User({username: currentUser})
    .fetch()
    .then(function(user) {
      user.save(data)
        .then(function() {
          res.end('updated');
        });
    });
});


router.post('/checkUser', function(req, res, done) {
  // console.log(req.body,'req..body');
  var currentUser = req.body.username;
  // check DB to see if current user has stripe information


  new User({username: currentUser})
    .fetch({
      withRelated: ['invites']
    })
    .then(function(user){

      // console.log('current invites', user.related('invites').models);
      if (user) {
        var inviteModels = user.related('invites').models;

        var currentInvites = [];
        for (var i = 0; i < inviteModels.length; i++) {

          if (inviteModels[i].attributes.joined || inviteModels[i].attributes.declined) {
            currentInvites.push(inviteModels[i].attributes.event_id)
          }
        }
      }

      // console.log(currentInvites);
      

     if (user) {

       if (user.attributes.venmoAccessToken && user.attributes.venmoUserId) {
         res.json({
           hasVenmoInfo: true,
           userID: user.attributes.id,
           relatedEventIds: currentInvites
         });

       } else {

         res.json({
           hasVenmoInfo: false,
           userID: user.attributes.id,
           relatedEventIds: currentInvites
         });
       }
{'fraction_non_alphanumeric': 0.15188856147870344, 'fraction_numerical': 0.0005357621216180017, 'mean_word_length': 2.431985294117647, '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': '1495993', 'n_tokens_mistral': 1136, 'n_tokens_neox': 1102, 'n_words': 220}