Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
491 additions
and
313 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,35 @@ | ||
/* ensure mongo uri */ | ||
process.env.MONGODB_URI = | ||
process.env.MONGODB_URI || 'mongodb://localhost/majifix-account'; | ||
|
||
/* dependencies */ | ||
const path = require('path'); | ||
const _ = require('lodash'); | ||
const async = require('async'); | ||
const mongoose = require('mongoose'); | ||
// mongoose.set('debug', true); | ||
const { get, mount, start } = require('@lykmapipo/express-common'); | ||
const { Jurisdiction } = require('@codetanzania/majifix-jurisdiction'); | ||
|
||
const { Account, accountRouter, apiVersion, info } = require(path.join( | ||
__dirname, | ||
'..' | ||
)); | ||
|
||
let samples = require('./samples')(20); | ||
|
||
/* connect to mongoose */ | ||
mongoose.connect(process.env.MONGODB_URI); | ||
|
||
/** | ||
* | ||
*/ | ||
function boot() { | ||
async.waterfall( | ||
[ | ||
function clear(next) { | ||
Account.remove(function(/* error, results */) { | ||
next(); | ||
}); | ||
}, | ||
|
||
function clearJurisdiction(next) { | ||
Jurisdiction.remove(function(/* error, results */) { | ||
next(); | ||
}); | ||
}, | ||
|
||
function seedJurisdiction(next) { | ||
const jurisdiction = Jurisdiction.fake(); | ||
jurisdiction.post(next); | ||
}, | ||
|
||
function seedAccounts(jurisdiction, next) { | ||
/* fake accounts */ | ||
samples = _.map(samples, function(sample, index) { | ||
if (index % 2 === 0) { | ||
sample.jurisdiction = jurisdiction; | ||
} | ||
return sample; | ||
}); | ||
Account.create(samples, next); | ||
}, | ||
], | ||
function(error, results) { | ||
/* expose module info */ | ||
get('/', function(request, response) { | ||
response.status(200); | ||
response.json(info); | ||
}); | ||
|
||
// mount routers | ||
mount(accountRouter); | ||
|
||
/* fire the app */ | ||
start(function(error, env) { | ||
console.log(`visit http://0.0.0.0:${env.PORT}/${apiVersion}/accounts`); | ||
}); | ||
const { connect, jsonSchema } = require('@lykmapipo/mongoose-common'); | ||
const { accountRouter, info, apiVersion } = require('../lib'); | ||
|
||
const startHttpServer = () => { | ||
get('/', (request, response) => { | ||
response.status(200); | ||
response.json(info); | ||
}); | ||
|
||
get(`/${apiVersion}/schemas`, (request, response) => { | ||
const schema = jsonSchema(); | ||
response.status(200); | ||
response.json(schema); | ||
}); | ||
|
||
// mount routers | ||
mount(accountRouter); | ||
|
||
// fire http serve | ||
start((error, env) => { | ||
if (error) { | ||
throw error; | ||
} | ||
); | ||
} | ||
|
||
boot(); | ||
console.log(`visit http://0.0.0.0:${env.PORT}/${apiVersion}/accounts`); | ||
}); | ||
}; | ||
|
||
// connect and start http server | ||
connect(error => { | ||
if (error) { | ||
throw error; | ||
} | ||
startHttpServer(); | ||
}); |
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
Oops, something went wrong.