Skip to content

Commit

Permalink
test: sample fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vijayg10 committed Nov 27, 2024
1 parent bc9d726 commit 50266b3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/domain/fx/cyril.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ const processFxFulfilMessage = async (commitRequestId) => {
* @param {Array<string>} transferIdList - List of transfer IDs to retrieve regular transfer-related position changes.
* @returns {Promise<PositionChangeItem[]>} - A promise that resolves to an array of position change objects.
*/
const _getPositionChanges = async (commitRequestIdList, transferIdList) => {
const _getPositionChanges = async (commitRequestIdList, transferIdList, originalId) => {
const positionChanges = []
for (const commitRequestId of commitRequestIdList) {
const fxRecord = await fxTransfer.getAllDetailsByCommitRequestIdForProxiedFxTransfer(commitRequestId)
Expand All @@ -239,6 +239,7 @@ const _getPositionChanges = async (commitRequestIdList, transferIdList) => {
positionChanges.push({
isFxTransferStateChange: true,
commitRequestId,
isOriginalId: originalId === commitRequestId,
notifyTo: fxRecord.externalInitiatingFspName || fxRecord.initiatingFspName,
participantCurrencyId: fxPositionChange.participantCurrencyId,
amount: -fxPositionChange.change
Expand All @@ -253,6 +254,7 @@ const _getPositionChanges = async (commitRequestIdList, transferIdList) => {
positionChanges.push({
isFxTransferStateChange: false,
transferId,
isOriginalId: originalId === transferId,
notifyTo: transferRecord.externalPayerName || transferRecord.payerFsp,
participantCurrencyId: transferPositionChange.participantCurrencyId,
amount: -transferPositionChange.change
Expand Down Expand Up @@ -280,7 +282,7 @@ const processFxAbortMessage = async (commitRequestId) => {
const relatedFxTransferRecords = await fxTransfer.getByDeterminingTransferId(fxTransferRecord.determiningTransferId)

// Get position changes
const positionChanges = await _getPositionChanges(relatedFxTransferRecords.map(item => item.commitRequestId), [fxTransferRecord.determiningTransferId])
const positionChanges = await _getPositionChanges(relatedFxTransferRecords.map(item => item.commitRequestId), [fxTransferRecord.determiningTransferId], commitRequestId)

histTimer({ success: true })
return {
Expand All @@ -299,7 +301,7 @@ const processAbortMessage = async (transferId) => {
const relatedFxTransferRecords = await fxTransfer.getByDeterminingTransferId(transferId)

// Get position changes
const positionChanges = await _getPositionChanges(relatedFxTransferRecords.map(item => item.commitRequestId), [transferId])
const positionChanges = await _getPositionChanges(relatedFxTransferRecords.map(item => item.commitRequestId), [transferId], transferId)

histTimer({ success: true })
return {
Expand Down
11 changes: 7 additions & 4 deletions src/domain/position/abort.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ const processPositionAbortBin = async (
for (const positionChange of cyrilResult.positionChanges) {
if (positionChange.isFxTransferStateChange) {
// Construct notification message for fx transfer state change
const resultMessage = _constructAbortResultMessage(binItem, positionChange.commitRequestId, from, positionChange.notifyTo)
const resultMessage = _constructAbortResultMessage(binItem, positionChange.commitRequestId, from, positionChange.notifyTo, positionChange.isOriginalId, true)
resultMessages.push({ binItem, message: resultMessage })
} else {
// Construct notification message for transfer state change
const resultMessage = _constructAbortResultMessage(binItem, positionChange.transferId, from, positionChange.notifyTo)
const resultMessage = _constructAbortResultMessage(binItem, positionChange.transferId, from, positionChange.notifyTo, positionChange.isOriginalId, false)
resultMessages.push({ binItem, message: resultMessage })
}
}
Expand Down Expand Up @@ -126,13 +126,16 @@ const processPositionAbortBin = async (
}
}

const _constructAbortResultMessage = (binItem, id, from, notifyTo) => {
const _constructAbortResultMessage = (binItem, id, from, notifyTo, isOriginalId, isFx) => {
let apiErrorCode = ErrorHandler.Enums.FSPIOPErrorCodes.PAYEE_REJECTION
let fromCalculated = from
if (binItem.message?.value.metadata.event.action === Enum.Events.Event.Action.FX_ABORT_VALIDATION || binItem.message?.value.metadata.event.action === Enum.Events.Event.Action.ABORT_VALIDATION) {
fromCalculated = Config.HUB_NAME
apiErrorCode = ErrorHandler.Enums.FSPIOPErrorCodes.VALIDATION_ERROR
}
if (!isOriginalId) {
fromCalculated = Config.HUB_NAME
}
const fspiopError = ErrorHandler.Factory.createFSPIOPError(
apiErrorCode,
null,
Expand All @@ -151,7 +154,7 @@ const _constructAbortResultMessage = (binItem, id, from, notifyTo) => {
const metadata = Utility.StreamingProtocol.createMetadataWithCorrelatedEvent(
id,
Enum.Kafka.Topics.POSITION,
binItem.message?.value.metadata.event.action, // This will be replaced anyway in Kafka.produceGeneralMessage function
(isFx && !isOriginalId) ? Enum.Events.Event.Action.FX_ABORT : binItem.message?.value.metadata.event.action, // This will be replaced anyway in Kafka.produceGeneralMessage function
state
)
const resultMessage = Utility.StreamingProtocol.createMessage(
Expand Down

0 comments on commit 50266b3

Please sign in to comment.