diff --git a/package-lock.json b/package-lock.json index 63449df2..70036651 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "quoting-service", - "version": "10.5.2", + "version": "10.5.3", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index a4e2719a..bcff7d75 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "quoting-service", "description": "Quoting Service hosted by a scheme", "license": "Apache-2.0", - "version": "10.5.2", + "version": "10.5.3", "author": "ModusBox", "contributors": [ "James Bush ", diff --git a/src/data/database.js b/src/data/database.js index 4b4fefcb..d8a63b98 100644 --- a/src/data/database.js +++ b/src/data/database.js @@ -341,15 +341,20 @@ class Database { * * @returns {promise} - id of the participant */ - async getParticipant (participantName, participantType) { + async getParticipant (participantName, participantType, currencyId, ledgerAccountTypeId) { try { const rows = await this.queryBuilder('participant') - .where({ - name: participantName, - isActive: 1 - }) - .select() - + .where({ 'participant.name': participantName }) + .andWhere({ 'pc.currencyId': currencyId }) + .andWhere({ 'pc.ledgerAccountTypeId': ledgerAccountTypeId }) + .andWhere({ 'pc.isActive': true }) + .andWhere({ 'participant.isActive': true }) + .innerJoin('participantCurrency AS pc', 'pc.participantId', 'participant.participantId') + .select( + 'participant.*', + 'pc.participantCurrencyId', + 'pc.currencyId' + ) if ((!rows) || rows.length < 1) { // active participant does not exist, this is an error if (participantType && participantType === LOCAL_ENUM.PAYEE_DFSP) { diff --git a/src/model/quotes.js b/src/model/quotes.js index f6eb651d..56796e76 100644 --- a/src/model/quotes.js +++ b/src/model/quotes.js @@ -164,8 +164,8 @@ class QuotesModel { throw ErrorHandler.CreateInternalServerFSPIOPError('Missing quoteRequest', null, fspiopSource) } - await this.db.getParticipant(fspiopSource, LOCAL_ENUM.PAYER_DFSP) - await this.db.getParticipant(fspiopDestination, LOCAL_ENUM.PAYEE_DFSP) + await this.db.getParticipant(fspiopSource, LOCAL_ENUM.PAYER_DFSP, quoteRequest.amount.currency, ENUM.Accounts.LedgerAccountType.POSITION) + await this.db.getParticipant(fspiopDestination, LOCAL_ENUM.PAYEE_DFSP, quoteRequest.amount.currency, ENUM.Accounts.LedgerAccountType.POSITION) } /** diff --git a/test/unit/data/database.test.js b/test/unit/data/database.test.js index fa5919f6..fd97a7e7 100644 --- a/test/unit/data/database.test.js +++ b/test/unit/data/database.test.js @@ -33,6 +33,7 @@ jest.mock('knex') const Knex = require('knex') const crypto = require('crypto') +const ENUM = require('@mojaloop/central-services-shared').Enum const Database = require('../../../src/data/database') const Config = require('../../../src/lib/config') @@ -786,19 +787,21 @@ describe('/database', () => { // Arrange const participantName = 'dfsp1' const participantType = LibEnum.PAYEE_DFSP + const currency = 'USD' + const ledgerAccountType = ENUM.Accounts.LedgerAccountType.POSITION const mockList = mockKnexBuilder( mockKnex, [{ participantId: 123 }], - ['where', 'select'] + ['where', 'andWhere', 'andWhere', 'andWhere', 'andWhere', 'innerJoin', 'select'] ) // Act - const result = await database.getParticipant(participantName, participantType) + const result = await database.getParticipant(participantName, participantType, currency, ledgerAccountType) // Assert expect(result).toBe(123) expect(mockList[0]).toHaveBeenCalledWith('participant') - expect(mockList[1]).toHaveBeenCalledWith({ name: participantName, isActive: 1 }) + expect(mockList[1]).toHaveBeenCalledWith({ 'participant.name': participantName }) expect(mockList[2]).toHaveBeenCalledTimes(1) }) @@ -806,14 +809,16 @@ describe('/database', () => { // Arrange const participantName = 'dfsp1' const participantType = LibEnum.PAYEE_DFSP + const currency = 'USD' + const ledgerAccountType = ENUM.Accounts.LedgerAccountType.POSITION mockKnexBuilder( mockKnex, undefined, - ['where', 'select'] + ['where', 'andWhere', 'andWhere', 'andWhere', 'andWhere', 'innerJoin', 'select'] ) // Act - const action = async () => database.getParticipant(participantName, participantType) + const action = async () => database.getParticipant(participantName, participantType, currency, ledgerAccountType) // Assert await expect(action()).rejects.toThrowError('Unsupported participant') @@ -823,14 +828,16 @@ describe('/database', () => { // Arrange const participantName = 'dfsp1' const participantType = LibEnum.PAYER_DFSP + const currency = 'USD' + const ledgerAccountType = ENUM.Accounts.LedgerAccountType.POSITION mockKnexBuilder( mockKnex, undefined, - ['where', 'select'] + ['where', 'andWhere', 'andWhere', 'andWhere', 'andWhere', 'innerJoin', 'select'] ) // Act - const action = async () => database.getParticipant(participantName, participantType) + const action = async () => database.getParticipant(participantName, participantType, currency, ledgerAccountType) // Assert await expect(action()).rejects.toThrowError('Unsupported participant') @@ -839,14 +846,16 @@ describe('/database', () => { it('handles an empty response with no participantType', async () => { // Arrange const participantName = 'dfsp1' + const currency = 'USD' + const ledgerAccountType = ENUM.Accounts.LedgerAccountType.POSITION mockKnexBuilder( mockKnex, [], - ['where', 'select'] + ['where', 'andWhere', 'andWhere', 'andWhere', 'andWhere', 'innerJoin', 'select'] ) // Act - const action = async () => database.getParticipant(participantName) + const action = async () => database.getParticipant(participantName, undefined, currency, ledgerAccountType) // Assert await expect(action()).rejects.toThrowError('Unsupported participant')