Skip to content

Commit

Permalink
Bugfix/fix participant lookup to use currency (#231)
Browse files Browse the repository at this point in the history
Fix for createPartyQuote not passing all values to getParticipant
  • Loading branch information
rmothilal authored Jul 2, 2020
1 parent 5442493 commit 9b87b67
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion 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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "quoting-service",
"description": "Quoting Service hosted by a scheme",
"license": "Apache-2.0",
"version": "10.5.4",
"version": "10.5.5",
"author": "ModusBox",
"contributors": [
"James Bush <james.bush@modusbox.com>",
Expand Down
17 changes: 9 additions & 8 deletions src/data/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ const util = require('util')
const Logger = require('@mojaloop/central-services-logger')
const ErrorHandler = require('@mojaloop/central-services-error-handling')
const MLNumber = require('@mojaloop/ml-number')
const Enum = require('@mojaloop/central-services-shared').Enum

const LOCAL_ENUM = require('../lib/enum')
const { getStackOrInspect } = require('../lib/util')
Expand Down Expand Up @@ -341,19 +342,19 @@ class Database {
*
* @returns {promise} - id of the participant
*/
async getParticipant (participantName, participantType, currencyId, ledgerAccountTypeId) {
async getParticipant (participantName, participantType, currencyId, ledgerAccountTypeId = Enum.Accounts.LedgerAccountType.POSITION) {
try {
const rows = await this.queryBuilder('participant')
.innerJoin('participantCurrency AS pc', 'pc.participantId', 'participant.participantId')
.innerJoin('participantCurrency', 'participantCurrency.participantId', 'participant.participantId')
.where({ 'participant.name': participantName })
.andWhere({ 'pc.currencyId': currencyId })
.andWhere({ 'pc.ledgerAccountTypeId': ledgerAccountTypeId })
.andWhere({ 'pc.isActive': true })
.andWhere({ 'participantCurrency.currencyId': currencyId })
.andWhere({ 'participantCurrency.ledgerAccountTypeId': ledgerAccountTypeId })
.andWhere({ 'participantCurrency.isActive': true })
.andWhere({ 'participant.isActive': true })
.select(
'participant.*',
'pc.participantCurrencyId',
'pc.currencyId'
'participantCurrency.participantCurrencyId',
'participantCurrency.currencyId'
)
if ((!rows) || rows.length < 1) {
// active participant does not exist, this is an error
Expand Down Expand Up @@ -458,7 +459,7 @@ class Database {
const enumVals = await Promise.all([
this.getPartyType(partyType),
this.getPartyIdentifierType(party.partyIdInfo.partyIdType),
this.getParticipant(party.partyIdInfo.fspId),
this.getParticipant(party.partyIdInfo.fspId, participantType, currency),
this.getTransferParticipantRoleType(participantType),
this.getLedgerEntryType(ledgerEntryType)
])
Expand Down
2 changes: 1 addition & 1 deletion test/unit/data/database.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ describe('/database', () => {
// Assert
expect(result).toBe(123)
expect(mockList[0]).toHaveBeenCalledWith('participant')
expect(mockList[1]).toHaveBeenCalledWith('participantCurrency AS pc', 'pc.participantId', 'participant.participantId')
expect(mockList[1]).toHaveBeenCalledWith('participantCurrency', 'participantCurrency.participantId', 'participant.participantId')
expect(mockList[2]).toHaveBeenCalledTimes(1)
})

Expand Down

0 comments on commit 9b87b67

Please sign in to comment.