diff --git a/src/index.js b/src/index.js index 39ab65c0..7382c05f 100644 --- a/src/index.js +++ b/src/index.js @@ -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) => { diff --git a/src/models/model.js b/src/models/model.js index 81593cd6..0dca5879 100644 --- a/src/models/model.js +++ b/src/models/model.js @@ -79,7 +79,8 @@ 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 }) { @@ -87,29 +88,25 @@ module.exports = class Model { 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))); } } }; diff --git a/src/package-lock.json b/src/package-lock.json index ebdd3d0d..6b1de95d 100644 --- a/src/package-lock.json +++ b/src/package-lock.json @@ -1,6 +1,6 @@ { "name": "mojaloop-simulator", - "version": "11.2.0", + "version": "11.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/src/package.json b/src/package.json index c743eaeb..70added6 100644 --- a/src/package.json +++ b/src/package.json @@ -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",