Created
July 1, 2015 17:02
-
-
Save curtislacy/2c5e93cd4c57f099d789 to your computer and use it in GitHub Desktop.
Terrifying search thing.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict'; | |
// var _ = require('lodash'); | |
var async = require('async'); | |
var config = require('config'); | |
var synapse = require('lib/synapse.js'); | |
var Sequelize = require('sequelize'); | |
var moment = require('moment'); | |
var sequelize = new Sequelize(config.db.uri, config.db.options); | |
var _ = require('lodash'); | |
var init = { | |
'db': require('lib/loadModels')(sequelize), | |
'config': config, | |
'utility': { | |
'dttemail': require('lib/dttemail') | |
} | |
}; | |
var errbit = require('lib/errbit'); | |
var TESTING = !!process.env.TESTING; // to prevent the main loop | |
sequelize.authenticate().complete(function (err) { | |
if (err) { | |
process.exit(1); | |
} | |
if (TESTING) { | |
return; // short circuit the spin for testing | |
} | |
checkBankAccountVerifications( function(error) { | |
if(error) { | |
console.log(error); | |
} | |
process.exit(); | |
}) | |
}); | |
function checkBankAccountVerifications( callback ) { | |
init.db.SynapseUser.findAll({ | |
'include': [ init.db.BankAccountVerification, init.db.User ] | |
}).complete( function (error, synapseUsers) { | |
if(error) { | |
return callback(error); | |
} | |
async.forEach( synapseUsers, | |
function(synapseUser, done1) { | |
if( synapseUser.BankAccountVerifications && synapseUser.BankAccountVerifications.length > 1 ) { | |
return synapse.getLinkedBanksForSynapseUser( synapseUser.User, synapseUser, init.db, | |
function(error, linkedBanks) { | |
if(error) { | |
return done1(error); | |
} | |
async.forEach( synapseUser.BankAccountVerifications, | |
function( bav, done2 ) { | |
if( !_.find(linkedBanks, { 'id': bav.bankId })) { | |
console.log( 'Could not find linked bank for BAV: ' + bav.id + ', bankId: ' + bav.bankId ); | |
console.log( synapseUser.User.username + '\'s linked banks (' + linkedBanks.length + '): ' + ( _.pluck( linkedBanks, 'id' )).toString()); | |
} | |
done2(); | |
}, | |
done1 ); | |
}); | |
} | |
done1(); | |
}, | |
function(error) { | |
return callback(error); | |
} ); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment