From be1261880a0792e9ba8e011e1c88ee5d92de6690 Mon Sep 17 00:00:00 2001 From: Kevin Leyow Date: Mon, 25 May 2020 13:50:20 -0500 Subject: [PATCH 1/3] Updated parties to support account information. --- src/docker-compose.yml | 2 +- src/models/constants.js | 13 ++++++++++ src/models/model.js | 2 ++ src/models/party.js | 53 ++++++++++++++++++++++++++++++++++++++--- src/test-api/api.yaml | 26 ++++++++++++++++++++ src/test/constants.js | 12 ++++++++++ src/test/model.js | 12 ++++++++++ 7 files changed, 116 insertions(+), 4 deletions(-) diff --git a/src/docker-compose.yml b/src/docker-compose.yml index acbafa1f..c5f3b5c1 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -19,4 +19,4 @@ services: - "3500:3000" - "3501:4000" depends_on: - - redis \ No newline at end of file + - redis diff --git a/src/models/constants.js b/src/models/constants.js index 0d8929ad..45bb3a1a 100644 --- a/src/models/constants.js +++ b/src/models/constants.js @@ -22,6 +22,7 @@ ******/ 'use strict'; +const partyAccountsTable = 'account'; const partyTable = 'party'; const quoteTable = 'quote'; const transactionRequestTable = 'transactionRequest'; @@ -78,6 +79,16 @@ CREATE TABLE IF NOT EXISTS ${transferTable} ( ) `; +const createAccountTable = ` +CREATE TABLE IF NOT EXISTS ${partyAccountsTable} ( + address TEXT NOT NULL PRIMARY KEY, + currency TEXT NOT NULL, + description TEXT NOT NULL, + idValue TEXT NOT NULL, + FOREIGN KEY (idValue) REFERENCES party(idValue) ON DELETE CASCADE +) +`; + module.exports = { partyTable, quoteTable, @@ -89,4 +100,6 @@ module.exports = { transferTable, partyExtensionTable, createPartyExtensionTable, + partyAccountsTable, + createAccountTable, }; diff --git a/src/models/model.js b/src/models/model.js index ea655476..5c659e59 100644 --- a/src/models/model.js +++ b/src/models/model.js @@ -40,6 +40,7 @@ const { createQuoteTable, createTransactionRequestTable, createPartyExtensionTable, + createAccountTable, } = require('./constants'); /** @@ -89,6 +90,7 @@ module.exports = class Model { await this.db.run(createTransactionRequestTable); await this.db.run(createTransferTable); await this.db.run(createPartyExtensionTable); + await this.db.run(createAccountTable); this.party = new Party(this.db); this.quote = new Quote(this.db); diff --git a/src/models/party.js b/src/models/party.js index bbff6198..df900112 100644 --- a/src/models/party.js +++ b/src/models/party.js @@ -28,7 +28,7 @@ * @description Defines the party model structure and operations within the simulator. */ -const { partyTable, partyExtensionTable } = require('./constants'); +const { partyTable, partyExtensionTable, partyAccountsTable } = require('./constants'); /** @@ -51,7 +51,12 @@ module.exports = class Party { */ async get(idType, idValue) { - const res = await this.db.all(`SELECT p.displayName, p.firstName, p.middleName, p.lastName, p.dateOfBirth, p.idType, p.idValue, pe.key, pe.value FROM ${partyTable} p LEFT JOIN ${partyExtensionTable} pe ON p.idValue = pe.idValue WHERE p.idType = ? AND p.idValue = ?`, [idType, idValue]); + const res = await this.db.all(` + SELECT p.displayName, p.firstName, p.middleName, p.lastName, p.dateOfBirth, p.idType, p.idValue, pe.key, pe.value, pa.address, pa.currency, pa.description + FROM ${partyTable} p + LEFT JOIN ${partyExtensionTable} pe ON p.idValue = pe.idValue + LEFT JOIN ${partyAccountsTable} pa ON p.idValue = pa.idValue + WHERE p.idType = ? AND p.idValue = ?`, [idType, idValue]); const resultMap = {}; res.forEach((row) => { let party; @@ -75,6 +80,16 @@ module.exports = class Party { } party.extensionList.push({ key: row.key, value: row.value }); } + if (row.address) { + if (!party.accounts) { + party.accounts = []; + } + party.accounts.push({ + address: row.address, + currency: row.currency, + description: row.description, + }); + } }); if (res.length && res.length > 0) { return Object.values(resultMap)[0]; @@ -89,7 +104,11 @@ module.exports = class Party { * @returns {Promise} Party object. */ async getAll() { - const res = await this.db.all(`SELECT p.displayName, p.firstName, p.middleName, p.lastName, p.dateOfBirth, p.idType, p.idValue, pe.key, pe.value FROM ${partyTable} p LEFT JOIN ${partyExtensionTable} pe ON p.idValue = pe.idValue`); + const res = await this.db.all(` + SELECT p.displayName, p.firstName, p.middleName, p.lastName, p.dateOfBirth, p.idType, p.idValue, pe.key, pe.value, pa.address, pa.currency, pa.description + FROM ${partyTable} p + LEFT JOIN ${partyExtensionTable} pe ON p.idValue = pe.idValue + LEFT JOIN ${partyAccountsTable} pa ON p.idValue = pa.idValue`); const resultMap = {}; res.forEach((row) => { let party; @@ -113,6 +132,16 @@ module.exports = class Party { } party.extensionList.push({ key: row.key, value: row.value }); } + if (row.address) { + if (!party.accounts) { + party.accounts = []; + } + party.accounts.push({ + address: row.address, + currency: row.currency, + description: row.description, + }); + } }); return Object.values(resultMap); } @@ -141,6 +170,15 @@ module.exports = class Party { [idValue, extension.key, extension.value]); }); } + if (party.accounts) { + const { accounts } = party; + accounts.forEach((account) => { + this.db.get(` + INSERT INTO ${partyAccountsTable} (idValue, address, currency, description) + VALUES (?, ?, ?, ?)`, + [idValue, account.address, account.currency, account.description]); + }); + } } @@ -181,6 +219,15 @@ module.exports = class Party { [idValue, extension.key, extension.value]); }); } + if (newParty.accounts) { + const { accounts } = newParty; + accounts.forEach((account) => { + this.db.run(` + INSERT OR IGNORE INTO ${partyAccountsTable} (idValue, address, currency, description) + VALUES (?, ?, ?, ?);`, + [idValue, account.address, account.currency, account.description]); + }); + } } /** diff --git a/src/test-api/api.yaml b/src/test-api/api.yaml index cb2c1053..07e3c860 100644 --- a/src/test-api/api.yaml +++ b/src/test-api/api.yaml @@ -173,6 +173,8 @@ components: maxLength: 128 extensionList: $ref: '#/components/schemas/ExtensionList' + accounts: + $ref: '#/components/schemas/AccountList' Extension: type: object required: @@ -193,6 +195,30 @@ components: $ref: '#/components/schemas/Extension' title: ExtensionList description: Data model for the complex type ExtensionList + Account: + type: object + required: + - address + - currency + - description + properties: + address: + type: string + description: The routable address of this account. + currency: + type: string + description: The currency of the account. + description: + type: string + description: The name of the account. + title: Account + description: Data model for the complex type Account + AccountList: + type: array + items: + $ref: '#/components/schemas/Account' + title: AccountList + description: Data model for the complex type accountList idType: type: string enum: diff --git a/src/test/constants.js b/src/test/constants.js index 92e86f86..c7f2a8fc 100644 --- a/src/test/constants.js +++ b/src/test/constants.js @@ -64,6 +64,18 @@ const partyCreate = { value: '12345343', }, ], + accounts: [ + { + currency: 'USD', + description: 'savings', + address: 'moja.blue.8f027046-b82a-4fa9-838b-514514543785', + }, + { + currency: 'USD', + description: 'checking', + address: 'moja.blue.8f027046-b82a-4fa9-838b-70210fcf8137', + }, + ], }; diff --git a/src/test/model.js b/src/test/model.js index aba1ac27..dcb55242 100644 --- a/src/test/model.js +++ b/src/test/model.js @@ -103,6 +103,18 @@ test('create and update a party', async (t) => { value: '12345343', }, ], + accounts: [ + { + currency: 'USD', + description: 'savings', + address: 'moja.blue.8f027046-b82a-4fa9-838b-100000000000', + }, + { + currency: 'USD', + description: 'savings', + address: 'moja.blue.8f027046-b82a-4fa9-838b-200000000000', + }, + ], }; await model.party.create(partyCreate); const orig = await model.party.get(idType, idValue); From a2a385c4076ce63d521b7087c08f5e7e7f99d2e1 Mon Sep 17 00:00:00 2001 From: Kevin Leyow Date: Mon, 25 May 2020 18:53:40 -0500 Subject: [PATCH 2/3] Added yars-parser to audit ignore list. --- src/audit-resolve.json | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) diff --git a/src/audit-resolve.json b/src/audit-resolve.json index 902945d6..370b7362 100644 --- a/src/audit-resolve.json +++ b/src/audit-resolve.json @@ -1,14 +1,32 @@ { - "1300|nyc>istanbul-reports>handlebars": { - "fix": 1 + "decisions": { + "1300|nyc>istanbul-reports>handlebars": { + "madeAt": 0, + "decision": "fix" + }, + "1316|nyc>istanbul-reports>handlebars": { + "madeAt": 0, + "decision": "fix" + }, + "1324|nyc>istanbul-reports>handlebars": { + "madeAt": 0, + "decision": "fix" + }, + "1325|nyc>istanbul-reports>handlebars": { + "madeAt": 0, + "decision": "fix" + }, + "1500|npm-audit-resolver>yargs-unparser>yargs>yargs-parser": { + "decision": "ignore", + "madeAt": 1590450688208, + "expiresAt": 1593042654156 + }, + "1500|npm-audit-resolver>audit-resolve-core>yargs-parser": { + "decision": "ignore", + "madeAt": 1590450692169, + "expiresAt": 1593042654156 + } }, - "1316|nyc>istanbul-reports>handlebars": { - "fix": 1 - }, - "1324|nyc>istanbul-reports>handlebars": { - "fix": 1 - }, - "1325|nyc>istanbul-reports>handlebars": { - "fix": 1 - } + "rules": {}, + "version": 1 } \ No newline at end of file From cd97f0452be102973ba550ee7529fc4af357cfe9 Mon Sep 17 00:00:00 2001 From: Kevin Leyow Date: Wed, 27 May 2020 06:48:38 -0500 Subject: [PATCH 3/3] Addressed comments. --- src/models/party.js | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/models/party.js b/src/models/party.js index df900112..737f083b 100644 --- a/src/models/party.js +++ b/src/models/party.js @@ -172,12 +172,10 @@ module.exports = class Party { } if (party.accounts) { const { accounts } = party; - accounts.forEach((account) => { - this.db.get(` - INSERT INTO ${partyAccountsTable} (idValue, address, currency, description) - VALUES (?, ?, ?, ?)`, - [idValue, account.address, account.currency, account.description]); - }); + await Promise.all(accounts.map(async (account) => this.db.get(` + INSERT INTO ${partyAccountsTable} (idValue, address, currency, description) + VALUES (?, ?, ?, ?)`, + [idValue, account.address, account.currency, account.description]))); } } @@ -221,12 +219,10 @@ module.exports = class Party { } if (newParty.accounts) { const { accounts } = newParty; - accounts.forEach((account) => { - this.db.run(` - INSERT OR IGNORE INTO ${partyAccountsTable} (idValue, address, currency, description) - VALUES (?, ?, ?, ?);`, - [idValue, account.address, account.currency, account.description]); - }); + await Promise.all(accounts.map(async (account) => this.db.run(` + INSERT OR IGNORE INTO ${partyAccountsTable} (idValue, address, currency, description) + VALUES (?, ?, ?, ?);`, + [idValue, account.address, account.currency, account.description]))); } }