Skip to content

Commit

Permalink
Improved Model.init doc. Fixed bug with server start. Bumped version. (
Browse files Browse the repository at this point in the history
  • Loading branch information
partiallyordered authored Sep 3, 2020
1 parent 900e19c commit f3e9a1f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 25 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const testApi = new Koa();

// Initialise the model
const model = new Model();
await model.init({ databaseFilePath: process.env.MODEL_DATABASE, parties: conf.parties });
await model.init({ databaseFilepath: process.env.MODEL_DATABASE, parties: conf.parties });

// Log raw to console as a last resort- if the logging framework crashes
const failSafe = async (ctx, next) => {
Expand Down
41 changes: 19 additions & 22 deletions src/models/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,37 +79,34 @@ module.exports = class Model {
* Initialises db.
*
* @async
* @param {String} databaseFilepath SqliteDB file path
* @param {String} databaseFilepath SqliteDB file path
* @param [{Object}] parties Array of party objects to create after db initialisation
* @throws {Error}
*/
async init({ databaseFilepath, parties }) {
if (this.db) {
throw new Error('Attempted to initialise database twice');
}

try {
this.db = await sqlite.open(databaseFilepath);
await this.db.run('PRAGMA foreign_keys = true');
await this.db.run(createPartyTable);
await this.db.run(createQuoteTable);
await this.db.run(createTransactionRequestTable);
await this.db.run(createTransferTable);
await this.db.run(createPartyExtensionTable);
await this.db.run(createBulkQuoteTable);
await this.db.run(createBulkTransferTable);
this.db = await sqlite.open(databaseFilepath);
await this.db.run('PRAGMA foreign_keys = true');
await this.db.run(createPartyTable);
await this.db.run(createQuoteTable);
await this.db.run(createTransactionRequestTable);
await this.db.run(createTransferTable);
await this.db.run(createPartyExtensionTable);
await this.db.run(createBulkQuoteTable);
await this.db.run(createBulkTransferTable);

this.party = new Party(this.db);
this.quote = new Quote(this.db);
this.bulkQuote = new BulkQuote(this.db);
this.transactionrequest = new TransactionRequest(this.db);
this.transfer = new Transfer(this.db);
this.bulkTransfer = new BulkTransfer(this.db);
this.party = new Party(this.db);
this.quote = new Quote(this.db);
this.bulkQuote = new BulkQuote(this.db);
this.transactionrequest = new TransactionRequest(this.db);
this.transfer = new Transfer(this.db);
this.bulkTransfer = new BulkTransfer(this.db);

if (parties) {
await Promise.all(parties.map((p) => this.party.create(p)));
}
} catch (err) {
throw new Error(err);
if (parties) {
await Promise.all(parties.map((p) => this.party.create(p)));
}
}
};
2 changes: 1 addition & 1 deletion src/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mojaloop-simulator",
"version": "11.2.0",
"version": "11.2.1",
"description": "A canonical test example implementation of the parties, transfers and quotes resources of the Mojaloop API",
"license": "Apache-2.0",
"main": "index.js",
Expand Down

0 comments on commit f3e9a1f

Please sign in to comment.