Browse files

Clean-up: server initialization

  • Loading branch information...
bnjbvr committed Jul 31, 2014
1 parent dafea8a commit f458312356ab61f36a0a3193100f18fa436bc1c2
Showing with 26 additions and 35 deletions.
  1. +0 −1
  2. +26 −34 server/
@@ -2,7 +2,6 @@ application = module.exports = (callback) ->
americano = require 'americano'
initialize = require './server/init'
require './tests/mock-weboob'
options =
name: 'pfm'
@@ -1,47 +1,39 @@
async = require 'async'
module.exports = (app, server, callback) ->
# Imports are within this scope, to ensure that americano-cozy is loaded
# before we load any model.
Bank = require './models/bank'
CozyInstance = require './models/cozyinstance'
AllBanksData = require "../tests/fixtures/banks-all.json"
# Bank initialization
console.log "Maybe Adding banks..."
Bank.all (err, banks) ->
if err or banks?.length is 0 # if there aren't any banks
async = require 'async'
CozyInstance = require './models/cozyinstance'
CozyInstance.getInstance (err, instance) ->
edenUrl = ""
if instance? and instance.helpUrl? and instance.helpUrl is edenUrl
bankListFile = "banks-mesinfos.json"
if err
console.error err
if banks?.length is 0 # if there aren't any banks
process = (bank, pcb) ->
Bank.create name:, uuid: bank.uuid, pcb
async.each AllBanksData, process, (finalErr) ->
# Final callback
if finalErr?
console.error "Error when adding bank: #{finalErr}"
bankListFile = "banks-all.json"
bankList = require "../tests/fixtures/#{bankListFile}"
process = (bank, callback) ->
Bank.create name:, uuid: bank.uuid, (err) ->
if err?
callback err
callback null
async.each bankList, process, (err) ->
if err?
msg = "Couldn't add the bank to the database -- #{err}"
console.log msg
msg = "Banks added to the database."
console.log msg
callback app, server if callback?
console.log "Success: All banks added."
callback app, server if callback?
console.log "Success: Banks were already present."
callback app, server if callback?
# Start bank polling
console.log "Start bank accounts polling..."
poller = require './lib/accounts-poller'
console.log "Starting bank accounts polling..."
# manage daily/weekly/monthly report
console.log "Start alert watcher..."
reportManager = require './lib/report-manager'
console.log "Starting alert watcher..."

0 comments on commit f458312

Please sign in to comment.