Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved Model.init doc. Fixed bug with server start. Bumped version. #78

Merged
merged 1 commit into from
Sep 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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